Skip to content

Make a failing instanceof, and a condition with no value, a real error - #353

Merged
ASDAlexander77 merged 1 commit into
mainfrom
fix-generic-instantiation-failure
Sep 23, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
fix-generic-instantiation-failure

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Summary

A failure inside the generated ___unbox<C> was swallowed. <C>anyValue compiled into a cast that always throws "Can't cast from any type", and no error was shown. Two bugs combined:

  • mlirGenInstanceOfOpaque reported failure as a null mlir::Value. ValueOrLogicalResult treats a null value as success with no value, so callers passed the failure on as a success. It now returns a ValueOrLogicalResult with a real failure on every path. Its internal EXIT_IF_FAILED_OR_NO_VALUE uses would have leaked "no value" the same way, so they are explicit failures now.

  • A condition with no value was taken for success. if and while used EXIT_IF_FAILED_OR_NO_VALUE, which returns the value itself; do and for checked only for failure. The new conditionHasValue rejects a present condition that yields no value, with "the condition has no value". The message is postponed like every other one and shown only if compilation fails. On main, with a void call as the condition:

    statement on main
    if generated nothing (exit 0, no output); in ___unbox it dropped the if (a instanceof C) return a; test
    for looped forever: no value is how for (;;) spells "no condition"
    do segfaulted (null mlir::Value)
    while failed with "empty block: expect at least a terminator"

    TypeScript also rejects testing a void value for truthiness.

Verification

  • With a temporary forced failure in mlirGenInstanceOfOpaque, the untyped-catch cast, plain instanceof and instanceof narrowing all stop with the real error. The first of those used to compile into an always-throwing cast.
  • New expected-error tests: test/tester/condition-value/{if,while,do,for}.ts. Each must print "the condition has no value", and must not print a stack dump or an assertion.
  • Windows Release: 2847/2847 passed.
  • Linux (WSL): 2841/2841 passed.

A correction to the note in #352: a failed generic instantiation does not leave its function in the module to be reused. The FuncOp is created detached and a failed body never reaches the module. The swallowing was entirely the two bugs above.

🤖 Generated with Claude Code

@ASDAlexander77
ASDAlexander77 merged commit 9cbb740 into main Sep 23, 2026
2 checks passed
@ASDAlexander77
ASDAlexander77 deleted the fix-generic-instantiation-failure branch September 23, 2026 20:19
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.

1 participant