Skip to content

scalac 3 can't compile code that worked with scalac 2 and Java, when extending Java class with lots of covariant overrides #18764

Closed
@lukaseder

Description

@lukaseder

Compiler version

3.3.1

Minimized code

The bug arises when using jOOQ generated code that compiles against the jOOQ runtime library. Download https://repo1.maven.org/maven2/org/jooq/jooq/3.18.7/jooq-3.18.7.jar, and then compile the following minimal reproducer:

import org.jooq.impl.TableRecordImpl

class TRecord extends TableRecordImpl[TRecord](null) {}

Compile with:

scalac -classpath jooq-3.18.7.jar Test.scala -explain

Output

-- [E164] Declaration Error: Test.scala:3:6 ------------------------------------
3 |class TRecord extends TableRecordImpl[TRecord](null) {}
  |      ^
  |error overriding method with in trait QualifiedRecord of type [T](x$0: org.jooq.Field[T], x$1: T): TRecord;
  |  method with² in class AbstractRecord of type [T](x$0: org.jooq.Field[T²], x$1: T²): org.jooq.Record has incompatible type;
  |other members with override errors are:: method original
  |
  |where:    T     is a type variable with constraint <: Object
  |          T²    is a type variable with constraint <: Object
  |          with  is a method in trait QualifiedRecord
  |          with² is a method in class AbstractRecord
  |-----------------------------------------------------------------------------
  | Explanation (enabled by `-explain`)
  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  | I tried to show that
  |   [T](x$0: org.jooq.Field[T], x$1: T): org.jooq.Record
  | conforms to
  |   [T](x$0: org.jooq.Field[T], x$1: T): TRecord
  | but the comparison trace ended with `false`:
  |
  |   ==> [T](x$0: org.jooq.Field[T], x$1: T): org.jooq.Record  <:  [T](x$0: org.jooq.Field[T], x$1: T): TRecord
  |     ==> type bounds []  <:  type bounds [] in frozen constraint
  |     <== type bounds []  <:  type bounds [] in frozen constraint = true
  |     ==> (x$0: org.jooq.Field[T], x$1: T): org.jooq.Record  <:  (x$0: org.jooq.Field[T], x$1: T): TRecord
  |       ==> org.jooq.Record  <:  TRecord
  |       <== org.jooq.Record  <:  TRecord = false
  |     <== (x$0: org.jooq.Field[T], x$1: T): org.jooq.Record  <:  (x$0: org.jooq.Field[T], x$1: T): TRecord = false
  |   <== [T](x$0: org.jooq.Field[T], x$1: T): org.jooq.Record  <:  [T](x$0: org.jooq.Field[T], x$1: T): TRecord = false
  |
  | The tests were made under the empty constraint
   -----------------------------------------------------------------------------
1 error found

Expectation

The code should compile just fine as it did with 2.13.12, for example, or in Scala. I think the lookup algorithm trips somewhere as it seems to find only the override [T](x$0: org.jooq.Field[T], x$1: T): org.jooq.Record, which is overridden covariantly to produce compatible versions.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions