Skip to content

-Xprint:all doesn't print type parameter bounds in the exported types #13306

@unkarjedy

Description

@unkarjedy

Compiler version

3.0.2-RC1

Minimized code

Compile this code with -Xprint:all compiler flag

class MyClass

class MembersContainer {
  type MyType[T <: MyClass] = Comparable[T]
}

object Exports {
  val instance = new MembersContainer
  export instance.*

  type Test = MyClass
  val x: MyType[Test] = new Comparable[Test] {
    override def compareTo(o: Test): Int = 0
  }
}

Output

Notice that for the synthetic type Exports.MyType type bounds are not printed in any phase.
Output example:

scalac: result of ...\src\main\scala\B.scala after typer:

scalac: package <empty> {
  class MyClass() extends Object() {}
  class MembersContainer() extends Object() {
    type MyType[T >: Nothing <: MyClass] = Comparable[T]
  }
  final lazy module val Exports: Exports = new Exports()
  final module class Exports() extends Object() { this: Exports.type =>
    val instance: MembersContainer = new MembersContainer()
    export Exports.instance.*
    final type MyType[T] = Comparable[T]
    type Test = MyClass
    val x: Exports.MyType[Exports.Test] = 
      {
        final class $anon() extends Object(), Comparable[Exports.Test] {
          override def compareTo(o: Exports.Test): Int = 0
        }
        new $anon():Comparable[Exports.Test]
      }
  }
}
...

notice no type parameter bounds

final type MyType[T] = Comparable[T]

However, if you replace type Test = MyClass with e.g. type Test = String the compiler will generate an error, indicating that the type parameter bound is there:

...\src\main\scala\B.scala:12:17
Type argument Exports.Test does not conform to upper bound MyClass
  val x: MyType[Test] = new Comparable[Test] {

Expectation

The type parameter bounds are printed for the exported synthetic members

Metadata

Metadata

Assignees

Labels

SpreeSuitable for a future Spreearea:reportingError reporting including formatting, implicit suggestions, etcgood first issuePerfect for someone who wants to get started contributingitype:enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions