From c5d3ef2fe5dd6569ec1f117b100cd1af2d66dfa7 Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Thu, 26 Oct 2023 13:19:45 +0200 Subject: [PATCH] [jOOQ/jOOQ#15760] Compile errors of generated classes using scala 3 --- .../java/org/jooq/codegen/JavaGenerator.java | 24 +++++++++++++------ pom.xml | 7 ++++++ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/jOOQ-codegen/src/main/java/org/jooq/codegen/JavaGenerator.java b/jOOQ-codegen/src/main/java/org/jooq/codegen/JavaGenerator.java index 37edf9d783..2b1ce76a0d 100644 --- a/jOOQ-codegen/src/main/java/org/jooq/codegen/JavaGenerator.java +++ b/jOOQ-codegen/src/main/java/org/jooq/codegen/JavaGenerator.java @@ -6818,8 +6818,10 @@ public class JavaGenerator extends AbstractGenerator { if (schemaId != null) { if (scala) { + + // [#15760] super.aliased() is necessary in Scala 3 out.println(); - out.println("%soverride def getSchema: %s = if (aliased()) null else %s", visibilityPublic(), Schema.class, schemaId); + out.println("%soverride def getSchema: %s = if (super.aliased()) null else %s", visibilityPublic(), Schema.class, schemaId); } else if (kotlin) { out.println("%soverride fun getSchema(): %s? = if (aliased()) null else %s", visibilityPublic(), Schema.class, schemaId); @@ -7493,7 +7495,8 @@ public class JavaGenerator extends AbstractGenerator { r.run(); }; - idt.accept(() -> out.println("%soverride def where(condition: %s): %s = new %s(getQualifiedName(), if (aliased()) this else null, condition)", visibilityPublic(), Condition.class, className, className)); + // [#15760] super.aliased() is necessary in Scala 3 + idt.accept(() -> out.println("%soverride def where(condition: %s): %s = new %s(getQualifiedName(), if (super.aliased()) this else null, condition)", visibilityPublic(), Condition.class, className, className)); idt.accept(() -> out.println("%soverride def where(conditions: %s[_ <: %s]): %s = where(%s.and(conditions))", visibilityPublic(), Collection.class, Condition.class, className, DSL.class)); idt.accept(() -> out.println("%soverride def where(conditions: %s*): %s = where(%s.and(conditions:_*))", visibilityPublic(), Condition.class, className, DSL.class)); idt.accept(() -> out.println("%soverride def where(condition: %s[%s]): %s = where(%s.condition(condition))", visibilityPublic(), Field.class, Boolean.class, className, DSL.class)); @@ -7743,7 +7746,8 @@ public class JavaGenerator extends AbstractGenerator { out.println("%s.value(%s, %s" + converterTemplateForTableValuedFunction(converter) + converterTemplateForTableValuedFunction(binding) + ")%s", DSL.class, paramArgName, paramTypeRef, converter, binding, separator); }); - out.println("), null)).map(r => if (aliased()) r.as(getUnqualifiedName) else r).get"); + // [#15760] super.aliased() is necessary in Scala 3 + out.println("), null)).map(r => if (super.aliased()) r.as(getUnqualifiedName) else r).get"); } else if (kotlin) { out.print("%sfun call(", visibility()).printlnIf(!parameters.isEmpty()); @@ -7802,8 +7806,11 @@ public class JavaGenerator extends AbstractGenerator { out.javadoc("Convenience mapping calling {@link %s#convertFrom(%s)}.", SelectField.class, Function.class); if (scala) { - out.println("%sdef mapping[U](from: (" + rowType + ") => U): %s[U] = convertFrom(r => from.apply(" + rangeClosed(1, degree).mapToObj(i -> "r.value" + i + "()").collect(joining(", ")) + "))", - visibility(), SelectField.class); + + // [#15760] Scala 3 has a type inference regression here, which is why we have to hint + // the lambda's r parameter type. + out.println("%sdef mapping[U](from: (" + rowType + ") => U): %s[U] = convertFrom((r: %s[" + rowType + "]) => from.apply(" + rangeClosed(1, degree).mapToObj(i -> "r.value" + i + "()").collect(joining(", ")) + "))", + visibility(), SelectField.class, out.ref("org.jooq.Record" + degree)); } else if (kotlin) { out.println("%sfun mapping(from: (" + rowType + ") -> U): %s = convertFrom(%s.mapping(from))", @@ -7819,8 +7826,11 @@ public class JavaGenerator extends AbstractGenerator { out.javadoc("Convenience mapping calling {@link %s#convertFrom(%s, %s)}.", SelectField.class, Class.class, Function.class); if (scala) { - out.println("%sdef mapping[U](toType: %s[U], from: (" + rowType + ") => U): %s[U] = convertFrom(toType,r => from.apply(" + rangeClosed(1, degree).mapToObj(i -> "r.value" + i + "()").collect(joining(", ")) + "))", - visibility(), Class.class, SelectField.class); + + // [#15760] Scala 3 has a type inference regression here, which is why we have to hint + // the lambda's r parameter type. + out.println("%sdef mapping[U](toType: %s[U], from: (" + rowType + ") => U): %s[U] = convertFrom(toType, (r: %s[" + rowType + "]) => from.apply(" + rangeClosed(1, degree).mapToObj(i -> "r.value" + i + "()").collect(joining(", ")) + "))", + visibility(), Class.class, SelectField.class, out.ref("org.jooq.Record" + degree)); } else if (kotlin) { out.println("%sfun mapping(toType: %s, from: (" + rowType + ") -> U): %s = convertFrom(toType, %s.mapping(from))", diff --git a/pom.xml b/pom.xml index 3c5db761bc..7f90dd1985 100644 --- a/pom.xml +++ b/pom.xml @@ -45,6 +45,7 @@ 2.13.11 + 3.3.1 1.8.0 @@ -399,6 +400,12 @@ 3.0.8 test + + org.scalatest + scalatest_3 + 3.2.14 + test +