Commit 1850335
committed
fix(semantic): validate inferred numeric literal values against their type
A suffix-less numeric literal (`let _x: u8 = 256;`, `match x { 256 => .. }`)
got a deferred `NumericLiteral` type var and was never value-validated — only
suffixed (`256_u8`) and const literals were. Out-of-range inferred literals
were silently accepted at semantic analysis and only caught later at lowering
(E3009).
Validate in `apply_inference_rewriter`: once a literal's type var is resolved,
report `E2008` for an out-of-range value (`LiteralError::OutOfRange` only — an
invalid literal type is already reported at conform time). The same
`handle_literal_rewrite` path covers both expression and pattern literals, so
these now error at semantic analysis instead of lowering.
This is now the single validation point for source literals in all contexts,
so the redundant per-literal check in const evaluation is dropped (const eval
bails on a prior error; computed const values are still validated where they
are evaluated). Add a regression test and refresh the lowering `literal`
golden (E3009 → E2008).1 parent 09bdf5e commit 1850335
9 files changed
Lines changed: 133 additions & 125 deletions
File tree
- crates
- cairo-lang-lowering/src
- lower
- flow_control
- create_graph
- test_data
- test_data
- cairo-lang-semantic/src
- expr
- test_data
- items
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | 7 | | |
9 | 8 | | |
10 | 9 | | |
| |||
43 | 42 | | |
44 | 43 | | |
45 | 44 | | |
46 | | - | |
| 45 | + | |
47 | 46 | | |
48 | 47 | | |
49 | 48 | | |
| |||
67 | 66 | | |
68 | 67 | | |
69 | 68 | | |
70 | | - | |
71 | 69 | | |
72 | 70 | | |
73 | 71 | | |
| |||
118 | 116 | | |
119 | 117 | | |
120 | 118 | | |
121 | | - | |
122 | 119 | | |
123 | 120 | | |
124 | 121 | | |
| |||
217 | 214 | | |
218 | 215 | | |
219 | 216 | | |
220 | | - | |
221 | 217 | | |
222 | 218 | | |
223 | 219 | | |
| |||
Lines changed: 12 additions & 30 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
647 | 647 | | |
648 | 648 | | |
649 | 649 | | |
650 | | - | |
651 | | - | |
652 | | - | |
653 | | - | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
654 | 654 | | |
655 | 655 | | |
656 | 656 | | |
| |||
671 | 671 | | |
672 | 672 | | |
673 | 673 | | |
674 | | - | |
675 | | - | |
676 | | - | |
677 | | - | |
678 | | - | |
| 674 | + | |
679 | 675 | | |
680 | 676 | | |
681 | 677 | | |
| |||
698 | 694 | | |
699 | 695 | | |
700 | 696 | | |
701 | | - | |
702 | | - | |
703 | | - | |
| 697 | + | |
704 | 698 | | |
705 | 699 | | |
706 | 700 | | |
| |||
711 | 705 | | |
712 | 706 | | |
713 | 707 | | |
714 | | - | |
715 | | - | |
716 | | - | |
717 | 708 | | |
718 | 709 | | |
719 | 710 | | |
| |||
775 | 766 | | |
776 | 767 | | |
777 | 768 | | |
778 | | - | |
779 | 769 | | |
780 | 770 | | |
781 | | - | |
| 771 | + | |
782 | 772 | | |
783 | | - | |
| 773 | + | |
784 | 774 | | |
785 | 775 | | |
786 | | - | |
787 | | - | |
788 | | - | |
789 | | - | |
790 | 776 | | |
791 | 777 | | |
792 | 778 | | |
| |||
795 | 781 | | |
796 | 782 | | |
797 | 783 | | |
798 | | - | |
| 784 | + | |
799 | 785 | | |
800 | 786 | | |
801 | 787 | | |
802 | 788 | | |
803 | 789 | | |
804 | 790 | | |
805 | | - | |
| 791 | + | |
806 | 792 | | |
807 | 793 | | |
808 | 794 | | |
| |||
825 | 811 | | |
826 | 812 | | |
827 | 813 | | |
828 | | - | |
829 | | - | |
830 | | - | |
831 | | - | |
832 | 814 | | |
833 | 815 | | |
834 | 816 | | |
| |||
Lines changed: 0 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
479 | 479 | | |
480 | 480 | | |
481 | 481 | | |
482 | | - | |
483 | | - | |
484 | | - | |
485 | | - | |
486 | | - | |
487 | | - | |
488 | | - | |
489 | | - | |
490 | | - | |
491 | 482 | | |
492 | 483 | | |
493 | 484 | | |
| |||
Lines changed: 32 additions & 23 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1498 | 1498 | | |
1499 | 1499 | | |
1500 | 1500 | | |
1501 | | - | |
1502 | | - | |
1503 | | - | |
1504 | | - | |
| 1501 | + | |
| 1502 | + | |
| 1503 | + | |
| 1504 | + | |
| 1505 | + | |
| 1506 | + | |
1505 | 1507 | | |
1506 | 1508 | | |
1507 | 1509 | | |
1508 | 1510 | | |
1509 | | - | |
1510 | | - | |
1511 | | - | |
| 1511 | + | |
1512 | 1512 | | |
1513 | 1513 | | |
1514 | 1514 | | |
1515 | 1515 | | |
1516 | | - | |
| 1516 | + | |
1517 | 1517 | | |
1518 | 1518 | | |
1519 | 1519 | | |
1520 | 1520 | | |
| 1521 | + | |
| 1522 | + | |
1521 | 1523 | | |
1522 | 1524 | | |
1523 | 1525 | | |
| |||
2032 | 2034 | | |
2033 | 2035 | | |
2034 | 2036 | | |
2035 | | - | |
2036 | | - | |
2037 | | - | |
| 2037 | + | |
2038 | 2038 | | |
2039 | 2039 | | |
2040 | 2040 | | |
2041 | 2041 | | |
| 2042 | + | |
| 2043 | + | |
2042 | 2044 | | |
2043 | 2045 | | |
2044 | 2046 | | |
| |||
2058 | 2060 | | |
2059 | 2061 | | |
2060 | 2062 | | |
2061 | | - | |
2062 | | - | |
2063 | | - | |
| 2063 | + | |
| 2064 | + | |
| 2065 | + | |
| 2066 | + | |
| 2067 | + | |
| 2068 | + | |
| 2069 | + | |
2064 | 2070 | | |
2065 | 2071 | | |
2066 | 2072 | | |
2067 | 2073 | | |
2068 | | - | |
2069 | | - | |
2070 | | - | |
| 2074 | + | |
2071 | 2075 | | |
2072 | 2076 | | |
2073 | 2077 | | |
2074 | 2078 | | |
| 2079 | + | |
| 2080 | + | |
2075 | 2081 | | |
2076 | 2082 | | |
2077 | 2083 | | |
| |||
2090 | 2096 | | |
2091 | 2097 | | |
2092 | 2098 | | |
2093 | | - | |
2094 | | - | |
2095 | | - | |
| 2099 | + | |
| 2100 | + | |
| 2101 | + | |
| 2102 | + | |
| 2103 | + | |
| 2104 | + | |
| 2105 | + | |
2096 | 2106 | | |
2097 | 2107 | | |
2098 | 2108 | | |
2099 | 2109 | | |
2100 | | - | |
2101 | | - | |
2102 | | - | |
| 2110 | + | |
2103 | 2111 | | |
2104 | 2112 | | |
2105 | 2113 | | |
2106 | 2114 | | |
| 2115 | + | |
2107 | 2116 | | |
2108 | 2117 | | |
2109 | 2118 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | | - | |
| 58 | + | |
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| |||
960 | 960 | | |
961 | 961 | | |
962 | 962 | | |
963 | | - | |
964 | | - | |
965 | | - | |
966 | | - | |
967 | | - | |
968 | | - | |
969 | | - | |
970 | | - | |
| 963 | + | |
971 | 964 | | |
972 | 965 | | |
973 | 966 | | |
| |||
0 commit comments