Skip to content

opaque type leads to wrong type inference #11255

Closed
@bohonghuang

Description

@bohonghuang

Compiler version

3.0.0-M3

Minimized code

  class A
  class B extends A
  
  object O {
    opaque type Id[T] = T
    extension[T](id: Id[T]) def get: T = id
    def f[S <: A, T](ff: S => T): Id[S => T] = ???
    def g[S <: A, T](ff: S => T): Option[S => T] = ???
    def h[S, T](ff: S => T): Id[S => T] = ???
  }
  
  import O._
  
  val a = new A
  val b = new B
  
  val f1/*: O.Id[Nothing => Int]*/ = f((a: A) => 0)
  f1.get.apply(a) //ERROR: Found: (a : A) Required: Nothing
  val f2 = f((b: B) => 0)
  f2.get.apply(b) //OK: works with B, the proper subtype of A
  
  val g1 = g((a: A) => 0)
  g1.get.apply(a) //OK: works without using opaque type
  
  val h1 = h((a: A) => 0)
  h1.get.apply(a) //OK: works without type bound

Metadata

Metadata

Assignees

No one assigned

    Labels

    backlogNo work planned on this by the core team for the time being.itype:bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions