-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Match types used in methods cause issues with inheritance #8666
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I guess this really messes with inheritance, since the overridden method is not necessarily the same as the super - so I'm not surprised that it doesn't compile. But the error message is perhaps not the best. It's a bit sad though that it wouldn't be possible to use this in |
That's not a new problem: you can override a method that takes an abstract |
It seems that the fundamental problem here is that we don't have enough subtyping rules for match types: scala> type Foo[A] = A match { case Int => String; case _ => Double }
scala> def foo[T](x: Foo[T]) = x
def foo[T](x: Foo[T]): Foo[T]
scala> foo("")
1 |foo("")
| ^^
| Found: ("" : String)
| Required: Foo[T]
|
| where: T is a type variable
scala> foo("": Foo[Int])
1 |foo("": Foo[Int])
| ^^^^^^^^^^^^
| Found: String
| Required: Foo[T]
|
| where: T is a type variable
scala> foo[Int]("")
val res0: String = "" I think what we should do when doing the subtype check: |
#8667 for another example |
I looked into this a bit more and I don't think that's realistic: match types can be so complicated than properly checking if a type is a subset of a match type given some type variable is going to be extremely expensive in general. On the other hand, it's really easy to check that scala> type Foo[A] = A match { case Int => String }
scala> val a: Foo[Int] = ""
val a: String = "" @OlivierBlanvillain Why is the type of scala> type Id[A] = A
// defined alias type Id[A] = A
scala> val x: Id[Int] = 1
val x: Id[Int] = 1 |
This fixes several erasure related things, such as signature, or erasure itself. Fixes scala#8666
This fixes several erasure related things, such as signature, or erasure itself. Fixes scala#8666
This fixes several erasure related things, such as signature, or erasure itself. Fixes scala#8666
Uh oh!
There was an error while loading. Please reload this page.
Minimized code
but it works fine if
bar
is pulled top-level:Then it compiles as expected.
Output
Expectation
Not sure - the error message needs improvement.
The text was updated successfully, but these errors were encountered: