Closed
Description
Compiler version
3.1.0
Minimized code
class Parent { class E }
object ChildA extends Parent
object ChildB extends Parent
class Printer[C <: Parent](val child: C):
def print(e: child.E): String = ""
Printer(ChildA).print(new ChildA.E) // does not work
Printer[ChildA.type](ChildA).print(new ChildA.E) // works
val p = Printer(ChildA); p.print(new ChildA.E) // works
Output
Found: Playground.ChildA.E
Required: Nothing
https://scastie.scala-lang.org/c1rQdb4BSgyv7ilyiiI0Zg
Expectation
This should compile. C
should be inferred as ChildA.type
, or a supertype of ChildA.type
which is later constrained to be a subtype of it too.
It works in Scala 2: https://scastie.scala-lang.org/IEMNML09TryqcA48OqVq2A. Maybe Scala 2 was inferring an existential here? But this program should not need existentials to type check.