Skip to content
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

CodeWriter generates wrong nullable type in function body #1759

Open
Tapchicoma opened this issue Dec 3, 2023 · 2 comments
Open

CodeWriter generates wrong nullable type in function body #1759

Tapchicoma opened this issue Dec 3, 2023 · 2 comments
Labels

Comments

@Tapchicoma
Copy link

Describe the bug

Consider I want to generate the following code:

class Test {
    fun doSomething(): Test? { 
        // do something
        return something as Test?
    }
}

kotlinpoet actually generates the following code:

class Test {
    fun doSomething(): Test? {
        // do something
        return something as ?Test
    }
}

I highly suspect that this line should be also called on !deferred condition. Otherwise ? is emitted immediately and the type is emitted somewhat later.

To Reproduce

I failed to reproduce this issue with unit test – it seems I lack the knowledge when deferred can be in true state and it is not happening in the simple case.

Please use the following steps to reproduce on a real project:

To debug generator run ./gradlew generateAPI -Dorg.gradle.debug=true and after build start attach debugger.

@Tapchicoma Tapchicoma added the bug label Dec 3, 2023
@Egorand
Copy link
Collaborator

Egorand commented Dec 5, 2023

I cloned the project and followed the steps to generate the code, but I can't seem to spot any broken type names in the files you mentioned, this is strange.. Would you be able to temporarily un-gitignore generated code folders on your machine and push that code to a separate branch? I'm really curious to take a look at the codegen code and try to reproduce this with a test!

@Tapchicoma
Copy link
Author

@Egorand please pull additional commit from the same branch.

chippmann added a commit to utopia-rise/godot-kotlin-jvm that referenced this issue Aug 18, 2024
This also prepares the api-gen for a kotlin poet update to the latest version. But because of square/kotlinpoet#1759 the update cannot be performed yet.
chippmann added a commit to utopia-rise/godot-kotlin-jvm that referenced this issue Aug 21, 2024
This also prepares the api-gen for a kotlin poet update to the latest version. But because of square/kotlinpoet#1759 the update cannot be performed yet.
chippmann added a commit to utopia-rise/godot-kotlin-jvm that referenced this issue Aug 21, 2024
This also prepares the api-gen for a kotlin poet update to the latest version. But because of square/kotlinpoet#1759 the update cannot be performed yet.
chippmann added a commit to utopia-rise/godot-kotlin-jvm that referenced this issue Aug 30, 2024
* Update kotlin to `2.0.10` and update other dependencies

This also prepares the api-gen for a kotlin poet update to the latest version. But because of square/kotlinpoet#1759 the update cannot be performed yet.

* Update kotlin to `2.0.20`

* Update docs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants