Skip to content

Fix: remove unnecessary !! operator in generated Kotlin code - #3833

Open
charlie-rbchd wants to merge 2 commits into
square:masterfrom
charlie-rbchd:fix/kotlin-generator-warnings
Open

charlie-rbchd wants to merge 2 commits into
square:masterfrom
charlie-rbchd:fix/kotlin-generator-warnings

Conversation

@charlie-rbchd

@charlie-rbchd charlie-rbchd commented Nov 27, 2026 •

Copy link
Copy Markdown

This PR is a follow-up to #3533 (related to #3467).

Some unnecessary double-bangs were left in the generated Kotlin code.

This made the upgrade to Kotlin 2.3 and later impossible for projects that have warning-as-error enabled.

@charlie-rbchd charlie-rbchd changed the title Remove unnecessary !! operator in generated Kotlin code Fix: remove unnecessary !! operator in generated Kotlin code Nov 27, 2026
addStatement("%N = %L(initialCapacity)", fieldName, ArrayList::class.simpleName)
endControlFlow()
addStatement("%L.tryDecode(reader, %N!!)", adapterName, fieldName)
addStatement("%L.tryDecode(reader, %N)", adapterName, fieldName)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The checked-in golden files still contain the old output. wire-golden-files/src/main/kotlin/squareup/wire/alltypes/AllTypes.kt has tryDecode(reader, pack_int32!!) and 25 similar calls (lines 4012 to 4441), and wire-golden-files/.../repeateddata/ParameterValue.kt:117 has tryDecode(reader, data_!!). CI does not catch this: its dirty-tree check runs after generateTests, which now generates only Swift, so the next local build rewrites these files and leaves an unexplained diff. Regenerate the golden files with ./gradlew :wire-golden-files:build and commit AllTypes.kt and ParameterValue.kt in this PR, as #3533 did.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it! I've regenerated the golden files.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants