-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Regression from Scala 2: Type variable in pattern match works with invariant type, fails with covariant #14739
Comments
This came up during the fix https://github.com/lampepfl/dotty/pull/14425/files, but the changes there are only in quotes so it's still broken now. |
I think that's because the Scala 2 version is unsound. I let @abgruszecki confirm. |
Unless you're referring to something else, I see now: it's not inferring the right type because it fears the type could have been refined to some unrelated type, i.e. why #11834 wants a warning. But List is sealed so it's plausible GADT reasoning could allow for that type to be inferred, I believe, as it sees that there are no funky mixing of List and another instantiation of IterableOps Also, this should work with the change I'm trying to make for that very issue #11834 by making funky mixes illegal. |
It's not an unsoundness problem, we definitely should be able to do better. In fact, we would do better if we had an unapply method that would do the typecheck for us, i.e. something like this:
This issue is just a deficiency in how we handle type case patterns. |
Scala 2.13.8 accepts both of these:
Scala 3 accepts the
Set
one, but fails on theList
version. with-explain
for verbosity,I assume that the difference between
Set
andList
here is thatSet
is invariant,List
covariant.(fyi @dwijnand; this came up during one of our pairing sessions)
The text was updated successfully, but these errors were encountered: