make unary prefix operators bind tighter than the as/is cast#74
make unary prefix operators bind tighter than the as/is cast#74Cintu07 wants to merge 2 commits into
Conversation
|
I encountered this problem. Let's create a poll on the Discord server. We should define the priority of the |
|
yeah worth pinning down. one scope note first: this PR only changes the a + b as int8 so rux already matches rust here: unary binds tighter than as, and as binds my vote is keep it as-is, matches rust/c and is the least surprising. are you |
|
The poll concluded just now, and the final decision is to parse a + b as uint8 as (a + b) as uint8. |
|
please resolve the conflicts. |
|
okok i will, sorry for late respomse |
|
I this more of a quality of life merge? |
08ec898 to
35b2815
Compare
this PR only changes the unary-vs-as level happy to do that one too. one thing to settle first, if as just becomes looser |
its a bug fix, not just QoL. right now p as int doesnt compile at all, it errors |
`*p as int` parsed as `*(p as int)` instead of `(*p) as int`, so dereferencing
through a cast failed to compile:
var x: int32 = 42;
let p = &x;
return *p as int; // error: '*' (dereference) applied to non-pointer type 'int'
`(*p) as int` and `*p` on its own both worked; only the combination broke. The
same affected -, ~, !, and & in front of a cast. The cause was the precedence
ladder placing ParseCast below ParseUnary, so the cast bound tighter than the
prefix operators.
Reorder the ladder to ParseExp -> ParseCast -> ParseUnary -> ParsePostfix so a
prefix operator applies before the cast, matching the usual precedence and the
language's own pointer examples. Chained casts, casts as binary operands, and
** are unchanged; the existing I/O, pow and unicode suites still pass.
Adds Tests/CastPrecedence and Tests/run_cast_precedence_test.sh, wired into CI
on all three platforms.
35b2815 to
5a5bb01
Compare
|
Right now this has merge conflicts. Could you rebase on dev, convert your test to the new format (i.e. Test.cmake instead of *.sh) and undo your changes in the workflows (as now it all goes through ctest)? Otherwise, the code looks good, I'll merge it if you apply the aforementioned suggestions. @Cintu07 |
|
I resolved the conflicts |
|
building doesn't work on linux, macOs and Windows, please fix |
found a precedence bug:
*p as intparses as*(p as int)instead of(*p) as int, so dereferencing through a cast doesnt compile:(*p) as int works, and *p on its own works, only the combo breaks. same thing
hits -, ~, !, & in front of a cast. the parser ladder had ParseCast below
ParseUnary so the cast bound tighter than the prefix ops.
reordered it to ParseExp -> ParseCast -> ParseUnary -> ParsePostfix so the prefix
applies first, matching the usual precedence and the pointer examples in the
docs. chained casts, casts as binary operands, and ** are unchanged, and the
existing io/pow/unicode suites still pass.
added Tests/CastPrecedence + run_cast_precedence_test.sh, wired into all 3 CI
workflows.