fix(compiler): diagnose optional binary operands - #9008
Conversation
christianwilkins
left a comment
There was a problem hiding this comment.
Reviewed head bf3abd00ce57b7ca21ca9b705d0643420b67bfd2, including the arithmetic diagnostic, the follow-up loop guards, the native fixtures, the optional-diagnostic helper, and the binary-operation dispatch around the new guard.
P2: runtime bitwise OR bypasses the new optional-operand check. With x: int | None, both x | 1 and 1 | x still produce no optional diagnostic. The union-annotation path already returns above this guard; exempting every BW_OR also exempts runtime operands. Please cover both directions and narrow the exemption to actual annotations.
Local validation: a direct JacProgram.compile probe with CompileOptions(force_codespace="native", force_target_program=True) produced E1121 for forward addition, reflected addition, and bitwise AND, but neither OR expression. Its assertion expecting all five diagnostics failed (3 reported); guarded addition and optional equality produced no errors. An initial test-helper import hit the existing ctypes-signature checking obstacle described in the PR. A separate temporary-change control did not finish compilation and is not counted as validation; the source was restored and the worktree is clean.
Current-head CI is green (25 successful checks, 3 skipped), but GitHub reports merge conflicts. Changes requested: fix and test runtime OR, resolve the conflicts while preserving the follow-up narrowing guards, and rerun validation/CI on the resulting head. Maintainer review/merge follows after those author actions.
| } | ||
| (magic, rmagic) = BINARY_OPERATOR_MAP[expr.op.name]; | ||
|
|
||
| if expr.op.name not in (Tok.EE, Tok.NE, Tok.BW_OR) { |
There was a problem hiding this comment.
[P2] Do not exempt runtime bitwise OR from the optional-operand diagnostic. The annotation-only OR case already returns at lines 354–363. Here, x | 1 and 1 | x with x: int | None skip the guard and still emit no E1121. A forced-native compile of those cases alongside x + 1, 1 + x, and x & 1 reports only the latter three errors. Limit the exemption to actual union annotations and add both runtime OR directions to the regression fixture.
Summary
Reproduction
Before this change,
jac check --native-coverageacceptedreturn x + 1forx: int | Nonewithout an optional-operand diagnostic. The attribute-access twin still reported its existing optional error.Verification
jac check --native-coverage /tmp/jac-8547-repro.jacreports E1121 forx + 1x + 1and1 + xctypestype signatures in the current test fileCloses #8547