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

Compilation error in KotlinGenerator generated code with KeepNamesGeneratorStrategy and generated implicit join paths #15946

Closed
lukaseder opened this issue Dec 18, 2023 · 2 comments

Comments

@lukaseder
Copy link
Member

lukaseder commented Dec 18, 2023

Discovered when writing tests for #15942, when using KeepNamesGeneratorStrategy with the KotlinGenerator and with implicit join paths, then there's a compilation error for a schema like this:

CREATE TABLE parent (
  id INT,
  CONSTRAINT pk_parent PRIMARY KEY (id)
);

CREATE TABLE "PascalCase" ("PascalCaseColumn" INT, CONSTRAINT fk_pascal_case FOREIGN KEY ("PascalCaseColumn") REFERENCES parent);
CREATE TABLE "camelCase" ("camelCaseColumn" INT, CONSTRAINT fk_camel_case FOREIGN KEY ("camelCaseColumn") REFERENCES parent);
CREATE TABLE "UPPER_CASE" ("UPPER_CASE_COLUMN" INT, CONSTRAINT fk_upper_case FOREIGN KEY ("UPPER_CASE_COLUMN") REFERENCES parent);
CREATE TABLE "lower_case" ("lower_case_column" INT, CONSTRAINT fk_lower_case FOREIGN KEY ("lower_case_column") REFERENCES parent);

Problematic code includes:

    override fun getReferences(): List<ForeignKey<org.jooq.codegen.test.keepnamesgeneratorstrategy.db.tables.records.lower_case, *>> = listOf(FK_LOWER_CASE)
    // Error here --------------------------------------------------------------------------------------------------------------------------- ^^^^^^^^^^^^^

    private lateinit var _FK_LOWER_CASE: PARENT_PATH

    /**
     * Get the implicit join path to the <code>PUBLIC.PARENT</code> table.
     */
    internal fun FK_LOWER_CASE(): PARENT_PATH {
        if (!this::_FK_LOWER_CASE.isInitialized)
            _FK_LOWER_CASE = PARENT_PATH(this, FK_LOWER_CASE, null) 
            // Error here -------------------- ^^^^^^^^^^^^^

        return _FK_LOWER_CASE;
    }

    internal val FK_LOWER_CASE: PARENT_PATH
        get(): PARENT_PATH = FK_LOWER_CASE()

And the compilation error is:

[ERROR] C:\Users\lukas\jOOQ\3.20\workspace\jOOQ-pro\jOOQ-test-codegen\jOOQ-test-codegen-kotlin\src\test\kotlin\org\jooq\codegen\test\keepnamesgeneratorstrategy\db\tables\lower_case.kt:[109,136] Type mismatch: inferred type is PARENT.PARENT_PATH but ForeignKey<lower_case, *> was expected
[ERROR] C:\Users\lukas\jOOQ\3.20\workspace\jOOQ-pro\jOOQ-test-codegen\jOOQ-test-codegen-kotlin\src\test\kotlin\org\jooq\codegen\test\keepnamesgeneratorstrategy\db\tables\lower_case.kt:[109,136] Type mismatch: inferred type is List<PARENT.PARENT_PATH> but List<ForeignKey<lower_case, *>> was expected
[ERROR] C:\Users\lukas\jOOQ\3.20\workspace\jOOQ-pro\jOOQ-test-codegen\jOOQ-test-codegen-kotlin\src\test\kotlin\org\jooq\codegen\test\keepnamesgeneratorstrategy\db\tables\lower_case.kt:[118,48] Type mismatch: inferred type is PARENT.PARENT_PATH but ForeignKey<out Record, PARENT>? was expected
@lukaseder
Copy link
Member Author

The fix is implemented with #15942, but parts of the fix can also be backported to older releases

@lukaseder lukaseder removed this from To do in 3.20 Other improvements Dec 18, 2023
@lukaseder lukaseder added this to To do in 3.14 Better Kotlin and Scala Support via automation Dec 18, 2023
3.14 Better Kotlin and Scala Support automation moved this from To do to Done Dec 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant