Skip to content

WIP Fix #9349#9354

Open
niclas-ahden wants to merge 5 commits intoroc-lang:mainfrom
niclas-ahden:test-expect-type-error-codegen-panic
Open

WIP Fix #9349#9354
niclas-ahden wants to merge 5 commits intoroc-lang:mainfrom
niclas-ahden:test-expect-type-error-codegen-panic

Conversation

@niclas-ahden
Copy link
Copy Markdown
Contributor

Add failing test for #9349 as per Zulip thread. This looks good to me, but I'd appreciate any feedback so that I can bring that into the future ones I'll create as well :)

…pect

Top-level `expect foo(Dynamite) == 5` where the argument is ill-typed
turns into a `runtime_error` LIR node; LIR codegen of the surrounding
`num_is_eq` then calls `exprLayout` on it and panics with
"LIR/codegen invariant violated: exprLayout called on non-value
expression runtime_error". The same expression inside `main!` reports
the type mismatch cleanly, so the bug is specific to `expect` codegen.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator

@Anton-4 Anton-4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @niclas-ahden :)

This looks good in general, can you add:

  • the issue number to the test description, so test "issue #9349: top-level expect with
  • Can you alter the test so that it expects the panic for now with the explanation in a comment? That way we can merge this in and make sure the code to run the test stays up to date.

@niclas-ahden
Copy link
Copy Markdown
Contributor Author

@Anton-4 Thanks for the feedback!

alter the test so that it expects the panic for now

I went with skipping the test for now with a TODO, which I think is what you meant, but let me know if you meant a literal expect of a panic.

If this is good I'll continue this way for the future tests :)

@Anton-4
Copy link
Copy Markdown
Collaborator

Anton-4 commented Apr 22, 2026

I went with skipping the test for now with a TODO, which I think is what you meant, but let me know if you meant a literal expect of a panic.

I thought about skipping at first but I believe that will lead to zig not building the code after the skip so it could become stale without us knowing. So I do think a literal expect of the panic is recommended here.

@Anton-4 Anton-4 self-assigned this May 4, 2026
Anton-4 and others added 2 commits May 4, 2026 19:41
When `lowerLowLevel` lowered an arg to a `runtime_error` LIR expression,
that noreturn expression slipped through ANF (it was marked atomic) and
landed directly in a low-level op's arg slot. The dev backend's
`exprLayout` invariant forbids being called on noreturn exprs, so
querying the operand layout for `num_is_eq` panicked.

Bubble up `runtime_error` in `lowerLowLevel`: if any lowered arg is a
`runtime_error`, replace the entire low-level call with a single
`runtime_error` carrying the call's ret layout. Accumulated let-bindings
for prior args (and their side effects) are preserved by `acc.finish`.

Also handle a top-level expression that returns `.noreturn` in dev
`generateCode` so we skip the result store when the trap has already
been emitted.

Unskip the previously-skipped repro in comptime_eval_test.zig.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Anton-4
Copy link
Copy Markdown
Collaborator

Anton-4 commented May 5, 2026

Expecting a panic in our case was not straightforward so I just fixed the issue :p
I still need to review it though.

@Anton-4 Anton-4 changed the title Add failing test for #9349 Fix #9349 May 5, 2026
@Anton-4 Anton-4 changed the title Fix #9349 WIP Fix #9349 May 5, 2026
@niclas-ahden
Copy link
Copy Markdown
Contributor Author

@Anton-4 Yeah, I also got stuck on expecting the panic. I wonder how tests like these should be written going forward? I did verify that skipping the test also skips compiling it, so it can rot as you said.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants