Skip to content

Strange type inference failure for module types #13842

Closed
@LPTK

Description

@LPTK

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions