Skip to content

Incorrect type error in a diamond class hierarchy #8933

Closed
@julienrf

Description

@julienrf

Minimized code

trait Foo[F[_]]

trait Top {
  type F[X]
  def foo: Foo[F]
}

trait Left extends Top

trait Right extends Top {
  trait F[X]
  def foo: Foo[F] = new Foo[F] {}
}

class Bottom extends Left with Right

Output

[error] -- Error:
[error] 17 |object Bottom extends Left with Right
[error]    |       ^
[error]    |method foo in trait Right is not a legal implementation of `foo` in class Bottom
[error]    |  its type             => Foo[Bottom.F]
[error]    |  does not conform to  => Foo[Bottom.F] & Foo[Bottom.F]

Expectation

The expected type for member foo in Bottom should be reduced to Foo[F] instead of Foo[F] & Foo[F], and the code would compile.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions