Skip to content

fix(aiken-lang): handle fail/todo constant eval without panic#1371

Open
knoal wants to merge 1 commit into
aiken-lang:mainfrom
knoal:fix/1344-v2
Open

fix(aiken-lang): handle fail/todo constant eval without panic#1371
knoal wants to merge 1 commit into
aiken-lang:mainfrom
knoal:fix/1344-v2

Conversation

@knoal

@knoal knoal commented Jul 2, 2026

Copy link
Copy Markdown

Fixes #1314.

What was wrong (original PR #1344)

The original fix used a blanket fallback for ALL eval errors. KtorZ correctly pointed out that silently swallowing every error changes compiler behaviour — a real problem (e.g. a broken cost model or internal bug) would now compile silently instead of being surfaced.

The fix (v2)

Explicitly match on the variant instead:

Test

Added which:

  1. Parses a module constant whose RHS calls a function returning
  2. Confirms codegen does NOT panic (the original crash)
  3. Confirms the generated term still fails at runtime (the correct behaviour)

All 180 gen_uplc tests pass.

Replace the blanket .unwrap_or_else(|e| panic!(...)) with explicit
match on the eval result:

- Err(Error::EvaluationFailure)  → fall back to the unevaluated term;
  this is correct because fail/todo terms are *supposed* to fail at
  runtime, not during constant folding in codegen.
- Err(any other error)           → propagate the panic; these indicate
  genuine problems we should not silently swallow.
- Ok(term)                       → use the evaluated constant as before.

This addresses KtorZ's review feedback on PR aiken-lang#1344: we no longer silently
change compiler behaviour for non-EvaluationFailure errors.

Fixes aiken-lang#1314.
@knoal knoal requested a review from a team as a code owner July 2, 2026 05:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Annotated fail constant panics during evaluation

1 participant