Skip to content

Match types used in methods cause issues with inheritance #8666

Closed
@felixmulder

Description

@felixmulder

Minimized code

class Foo[A, B]()

type FooSnd[X] = X match
  case Foo[_, b] => b

trait Bar[A]:
  def bar(h: FooSnd[A]): Int

val foo: Bar[Foo[String, Int]] = new Bar[Foo[String, Int]]:
  def bar(h: FooSnd[Foo[String, Int]]) = h

but it works fine if bar is pulled top-level:

- val foo: Bar[Foo[String, Int]] = new Bar[Foo[String, Int]]:
-   def bar(h: FooSnd[Foo[String, Int]]) = h
+ def bar(h: FooSnd[Foo[String, Int]]) = h

Then it compiles as expected.

Output

[error] -- Error: /Users/fixel/.src/fix-me-olivier.scala:19:6
[error] 19 |  def bar(h: FooSnd[Foo[String, Int]]) = h
[error]    |      ^
[error]    |error overriding method bar in trait Bar of type (h: FooSnd[Foo[String, Int]]): Int;
[error]    |  method bar of type (h: Int): Int has incompatible type

Expectation

Not sure - the error message needs improvement.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions