Skip to content

The truthiness of an any holding an object is true - #607

Merged
ASDAlexander77 merged 1 commit into
mainfrom
any-truthiness-objects
Oct 18, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
any-truthiness-objects

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Summary

if (a), !a and a ? x : y on an any holding a class instance, an object literal or an array threw "Can't cast from any type" at run time ("uncaught exception").

The cause: truthiness of an any goes through the generated ___unbox<boolean> (castPrimitiveTypeFromAny, MLIRGenCast.cpp). It answers primitive tags, null and undefined, and ended in a throw for everything else. Every falsy value (0, NaN, "", false, null, undefined, 0n) is a primitive answered there, so for a boolean target the remaining case now returns true, as JavaScript does. Every other target type keeps the throw.

Found while writing the stack-promotion tests (#605).

Tests

  • New 00any_truthiness_objects.ts covers a class instance, an object literal and an array (truthy), plus 0, "" and null (still falsy). It's registered for the default model (JIT and AOT) and in the rc/none corpus. It failed with "uncaught exception" before the fix.
  • Full suite: 4661/4661.

🤖 Generated with Claude Code

if (a), !a and a ? x : y of an any holding a class instance, an object
literal or an array threw "Can't cast from any type": the generated
___unbox<boolean> answered only primitive tags. Every falsy value is a
primitive answered there, so what is left is truthy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit f580ed8 into main Oct 18, 2026
2 checks passed
@ASDAlexander77
ASDAlexander77 deleted the any-truthiness-objects branch October 18, 2026 20:15
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