-
Notifications
You must be signed in to change notification settings - Fork 449
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
Pattern matching for chars are broken #5557
Comments
Indeed thanks for reporting. Moving to the syntax repo. |
What makes this a syntax problem? Is this also unicode related? |
No quotes are added in the generated code. |
Which means it's probably a compiler problem. |
Not sure what the issue is. The generated code looks file. |
The above function isA(c) {
if (c === 97) {
return true;
}
throw {
RE_EXN_ID: "Match_failure",
_1: [
"Main.res",
2,
2
],
Error: new Error()
};
} |
Got it. |
So the |
It seems to be only for chars, e.g. not strings or integers. That's peculiar. |
Didn't see this happening with other types. just char and char interval (which is the same from typechecker pov) |
Did something change with Unicode support? I remember chars now accepting codepoints |
I've chased down pattern matching to receiving an integer constant, and presumably expecting a char constant. I think there's no way to change the type of char without adapting the pattern matching also. As the notion of exhaustive matching would change. @IwanKaramazow do you have any thoughts? |
@amiralies is it true that the only issue you have observed is the detection of exhaustiveness? |
Perhaps one possibility would be to make char be an alias to int, and try to get int exhaustive matching to kick in. But is that even right? |
Yes. I'm not sure if there are other problems or no. ie
shows a warning |
Seems like it's a lot more involved cf. the original doc: https://docs.google.com/document/d/1V99iVjIncN7seNe-oECa_PU7Sx4ajz8xIH-qDg1vS6Y/edit |
I've moved it to milestone v10.1 so there's a little time to figure it out. |
…t working Fixes #5557 Fixes #5743 Exhaustiveness check for pattern matching relies on checking that the pattern does not lead to a type error. Since char constants are represented internally as int, this causes an internal type error when processing patterns of the form 'x', where the constant is represented as `Pconst_integer` but the expected type is `char`. This PR intercepts this situation and changes the expected type to `int`. A cleaner solution would be to represent chars differently (but we can't change the AST), or make it official that char and int is the same type (and lose some abstraction).
#5744) * Fix issue where exhaustiveness check for pattern matching char was not working Fixes #5557 Fixes #5743 Exhaustiveness check for pattern matching relies on checking that the pattern does not lead to a type error. Since char constants are represented internally as int, this causes an internal type error when processing patterns of the form 'x', where the constant is represented as `Pconst_integer` but the expected type is `char`. This PR intercepts this situation and changes the expected type to `int`. A cleaner solution would be to represent chars differently (but we can't change the AST), or make it official that char and int is the same type (and lose some abstraction). * comment
This is correct and seems cleaner. Maybe type char = private int ? |
That would be nice, though not sure how one would do that in practice. |
Specifically the constant |
add a test case snapshot
add a test case snapshot change Pconst_char payload (WIP) tweak tweak representation of char for lambda lib bugfix: replace wrong pp libs bugfix: replace wrong print use unsafe_chr to handle possible overflow char safe print int as char reduce duplication (re)use encodeCodepoint to support string_of_int_as_char some refactor libs CHANGELOG.md
add a test case snapshot change Pconst_char payload (WIP) representation of char for lambda safe print int as char reduce duplication (re)use encodeCodepoint to support string_of_int_as_char some refactor CHANGELOG.md some cleanup CHANGELOG.md
add a test case snapshot change Pconst_char payload (WIP) representation of char for lambda safe print int as char reduce duplication (re)use encodeCodepoint to support string_of_int_as_char some refactor CHANGELOG.md changelog
produces this
without warnigs.
The text was updated successfully, but these errors were encountered: