-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Improve error: the pattern contains an unaccounted type parameter #22943
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
Works correctly with LTS, including 3.3.5 and 3.3.6-RC1 So the faulty commit is somewhere in between 90f9d22..ec2b8bc |
It looks to be as designed per the spec, although the error message is misleading. The match type can be rewritten as follows to make it a legal match type: type KeysOf[KVs] = KVs match
case KV[k, v] => k
case Append[init, kv] =>
kv match
case KV[k, v] => KeysOf[init] | k Generally, only the deepest type constructor before type variables can be non-covariant. The 1-to-(n-1) outer type constructors must be covariant. |
Yes, it would be nice to have a better error message. |
@sjrd It's twice-nested invariant constructors (not contravariant). But anyway, the spec does list |
Ah yes, twice nested invariant, indeed. But yes, that's intentional. And no, it's not an implementation detail leaking into the spec. This spec was entirely developed on paper before I did whatever it took to implement. I don't remember exactly the reason for this one right now, but I remember there was a reason. Overall it's because matching is defined in terms of |
So a pattern trait A
trait B extends A
type Foo[T] = T match
case A => String
case B => Int
summon[Foo[B] =:= String] // OK
summon[Foo[B] =:= Int] // Error: Cannot prove that String =:= Int. (https://scastie.scala-lang.org/w4n3iRbmTR2nm2J8c91nzw) I still don't see why
|
Nested Variance does not work the same as elsewhere because we have tocapture type parameters in a way that survives type narrowing. |
I'm not sure I'm following. Is it a matter of giving the typechecker an intermediate variable (
Maybe an example would help. |
Compiler version
3.6.4
Minimized code
Output
https://scastie.scala-lang.org/6ZDIroNFQQuOwgG78Ju83w
Expectation
Should compile.
The text was updated successfully, but these errors were encountered: