Skip to content

Overridden member type does not conform to type projection on supertype #8338

Closed
@Jasper-M

Description

@Jasper-M

minimized code

object test {
  trait B { type X; def mkX(i: Int): B#X }
  val b: B = new B { type X = Int; def mkX(i: Int): X = i }
}

Compilation output

-- Error: test.scala:3:39 ------------------------------------------------------
3 |  val b: B = new B { type X = Int; def mkX(i: Int): X = i }
  |                                       ^
  |        error overriding method mkX in trait B of type (i: Int): test.B#X;
  |          method mkX of type (i: Int): X has incompatible type
1 error found

expectation

Should compile. Note that this already compiles:

trait B { type X; def mkX(i: Int): X }
val b: B = new B { type X = Int; def mkX(i: Int): X = i }
implicitly[b.X <:< B#X]

From the outside X is a subtype of B#X but inside new B { } not.

Related issue: #538

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