Commit 124f1ad
committed
Fix issue when inlining complex constants in pattern matching.
The compiler's back-end has optimisations to inline complex constants.
This can interfere with pattern matching compilation.
In the tests, a person can be a Student or a Teacher.
Because of inlining, the value one pattern matches on is known to be of type Teacher.
However, the compilation of pattern matching still generates code for both student and teacher.
The (dead) code for student is generated, but the inlined value has type teacher. This means that an attempt is made to access non-existent field "status" of teacher.
Notice one could even rename "status" to "age" in Student, and the filed would exist, but just be of unexpected type.
So the constant age for Teacher is interpreted as a status value (the second field of the inline record).
The compiler optimisation expects to find a valid constant for status, while it finds the age.
This PR catches this situation and does not try to follow a specific branch of the "status" cases but reverts to the general case.1 parent 7e776d0 commit 124f1ad
File tree
5 files changed
+107
-4
lines changed- jscomp
- core
- test
5 files changed
+107
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
405 | 405 | | |
406 | 406 | | |
407 | 407 | | |
408 | | - | |
409 | | - | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
410 | 413 | | |
411 | | - | |
| 414 | + | |
| 415 | + | |
412 | 416 | | |
413 | 417 | | |
414 | 418 | | |
| |||
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
0 commit comments