-
Notifications
You must be signed in to change notification settings - Fork 289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix KT-18706 in CodeWriter.generateImports #1920
Conversation
Can you write an integration test? In general we prefer to test against the public API and generated code so that we can ensure we cover the cases that consumers see. The unit tests are sufficient for coverage of the new function's behavior, but we need to see it wired up in practice at least once. |
@JakeWharton Sure, no problem. Can you please navigate me a bit, where are exactly other integration tests in this project? |
If your change doesn't affect imports you can write tests for the kotlinpoet/kotlinpoet/src/commonTest/kotlin/com/squareup/kotlinpoet/TypeAliasSpecTest.kt Line 34 in d2090c3
If it does affect imports, add a test to kotlinpoet/kotlinpoet/src/commonTest/kotlin/com/squareup/kotlinpoet/FileSpecTest.kt Lines 912 to 937 in d2090c3
|
@JakeWharton I think you've confused import aliases with This PR only affects import aliases, and only the code that generates them in cases where there's more than one type with the same simple name is used in CodeBlock I've just added another test specifically for that case, but I've put it in separate file. Is that ok? |
Ah, all the more reason it needed an integration test. There's no indication what actual output the change it affecting without close inspection. I would expect this test to change: kotlinpoet/kotlinpoet/src/commonTest/kotlin/com/squareup/kotlinpoet/FileSpecTest.kt Lines 425 to 447 in d2090c3
FileSpec I would prefer any tests for it to go under FileSpecTest , especially since we already have import alias test cases there and below in that link.
|
At first I tried to fix this case too, but as I said earlier, it became too complicated without rewriting So I decided to fix just the internal code inside
Done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
@mitasov-ra one more thing: could you please update the "Unreleased" section of the changelog? Thanks! |
@Egorand All done! Please rerun checks |
docs/changelog.md
Outdated
@@ -6,6 +6,7 @@ Change Log | |||
* **Fix**: Don't expand typealiases of function types to `LambdaTypeName`s in `KSTypeReference.toTypeName()`. | |||
* **Fix**: Small double and float values were set to 0.0 in %L translation (#1919) | |||
* **Fix**: Fix typealias type argument resolution in KSP2. | |||
* **Fix**: Fix KT-18706 in CodeWriter.generateImports (#1920) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we change this to be a bit more user friendly so someone reading this would understand what the impact on their code is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated changelog, if new description is still seems off to you, please provide your version
All looks good to me, thanks! @JakeWharton please merge if you're happy with the changes. |
@mitasov-ra looks like there are conflicts blocking the merge (sorry for the delay in merging your PR), and it doesn't seem like I can resolve them myself - can you please rebase? I'm in the process of releasing 1.18.0, and will release 1.18.1 with your change once the PR is merged. Thanks! |
@Egorand Done |
Merged, thank you! |
docs/changelog.md
has been updated if applicable.Because of KT-18706
bug all aliases escaped with backticks are not resolved by the Kotlin compiler.
So I've added a new function to Utils -
String.escapeAsAlias
, which converts aliases to Java identifiers, so that backticks are no longer needed.I tried to make a more "global" fix by adding
escapeAsAlias
to theImport
constructor, but sinceImport
is adata class
the "easy way" is not possible.Import
should be converted toclass
to do this.So I've decided just to fix the
generateImports
function, so that aliases, generated by kotlinpoet itself, would work. This small fix helps a lot with code generation tools.