-
-
Notifications
You must be signed in to change notification settings - Fork 418
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
Forbid impossible pattern matching on generic capabilities #2499
Conversation
@Praetonus we discussed this during sync and we aren't sure from your commit what this does. we think we know, but we aren't sure. can you give an example of what would be disallowed with this change (and ideally what currently happens in that case). |
@Praetonus - I think I understand the goal of this (in that it's an extension of detecting impossible match at runtime), but I'm concerned about recommending |
Let's take this code as an example: fun foo[A: Any #send](a: A) =>
match a
| let a': Any val => print("val")
else
print("other")
end In the current state of things, a The above code is effectively equivalent to the following version with fun foo[A: Any #send](a: A) =>
iftype A <: Any val then
print("val")
else
print("other")
end The main motivation here is to catch potential mistakes with I don't think recommending |
Do you think it would make sense to write a testcase that shows an example of what is forbidden now and asserts on the match error? |
This changes the capability rules for pattern matching from "some possible instantiation of the operand is a subtype of some possible instantation of the pattern" to "every possible instantiation of the operand is a subtype of every possible instantiation of the pattern". In practice this makes the compiler issue an error when a pattern can only ever match for some reification of the generic capability. Code that uses this kind of pattern matching should now use `iftype` instead. This doesn't fix any safety issues.
1cfa808
to
bf1b2a1
Compare
I've added a test. |
Forgot about that one. Merging now. |
…2499) This changes the capability rules for pattern matching from "some possible instantiation of the operand is a subtype of some possible instantation of the pattern" to "every possible instantiation of the operand is a subtype of every possible instantiation of the pattern". In practice this makes the compiler issue an error when a pattern can only ever match for some reification of the generic capability. Code that uses this kind of pattern matching should now use `iftype` instead. This doesn't fix any safety issues.
This changes the capability rules for pattern matching from
"some possible instantiation of the operand is a subtype of some possible instantation of the pattern"
to
"every possible instantiation of the operand is a subtype of every possible instantiation of the pattern".
In practice this makes the compiler issue an error when a pattern can only ever match for some reification of the generic capability. Code that uses this kind of pattern matching should now use
iftype
instead.This doesn't fix any safety issues.