Skip to content
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

Fatal error: Matching.comp_exit on switch ... if #5743

Closed
liweijian opened this issue Oct 19, 2022 · 1 comment
Closed

Fatal error: Matching.comp_exit on switch ... if #5743

liweijian opened this issue Oct 19, 2022 · 1 comment
Labels
Milestone

Comments

@liweijian
Copy link

Hi, I got an fatal error :

>> Fatal error: Matching.comp_exit
Fatal error: exception Whole_compiler.Misc.Fatal_error
FAILED: cannot make progress due to previous errors.

With the minimal test case:

let is_digit = c => c >= '0' && c <= '9'

let head_char = c => switch c {
| '(' => Js.log("got lparen")
| ')' => Js.log("got rpare")
| c if is_digit(c) => Js.log("got num")
}

With VSCode information:
image

Just wondering if anything I'd missed?

@cristianoc
Copy link
Collaborator

Probably related: #5557

@cristianoc cristianoc added the bug label Oct 19, 2022
@cristianoc cristianoc added this to the v11.0 milestone Oct 19, 2022
cristianoc added a commit that referenced this issue Oct 19, 2022
…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).
cristianoc added a commit that referenced this issue Oct 19, 2022
#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
bobzhang added a commit that referenced this issue Oct 24, 2022
butterunderflow pushed a commit to butterunderflow/rescript-compiler that referenced this issue Oct 31, 2022
butterunderflow pushed a commit to butterunderflow/rescript-compiler that referenced this issue Oct 31, 2022
butterunderflow pushed a commit to butterunderflow/rescript-compiler that referenced this issue Oct 31, 2022
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
butterunderflow pushed a commit to butterunderflow/rescript-compiler that referenced this issue Oct 31, 2022
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
butterunderflow pushed a commit to butterunderflow/rescript-compiler that referenced this issue Oct 31, 2022
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants