Skip to content

json stringify with mixed-type variables and type assertions#74

Merged
cs01 merged 3 commits intomainfrom
worktree-fix-json-stringify-mixed-types
Mar 1, 2026
Merged

json stringify with mixed-type variables and type assertions#74
cs01 merged 3 commits intomainfrom
worktree-fix-json-stringify-mixed-types

Conversation

@cs01
Copy link
Owner

@cs01 cs01 commented Mar 1, 2026

fix: json stringify with mixed-type variables and type assertions

Summary

  • JSON.stringify({ ... } as any) crashed at LLVM opt: the as type assertion wraps the object in a TypeAssertionNode, so arg.type === "type_assertion" instead of "object", bypassing stringifyObjectLiteral and falling through to stringifyNumber. That called generateExpression on the whole object, bitcast the struct pointer to i8*, then passed it as double to sprintf — a type mismatch that opt -O2 rejects.
  • Fix: unwrap type_assertion nodes in generateStringify before dispatch, using a named TypeAssertionNode cast (avoids phi node metadata loss from inline as { ... } struct assertions); extract generateStringifyArg() helper.
  • Two regression tests added: mixed string+number variable values, and an inline object with a type assertion.

Test plan

  • json stringify inline object with mixed string and number variable values passes
  • json stringify inline object with type assertion does not crash passes
  • All pre-existing JSON stringify tests still pass

@cs01 cs01 changed the title fix json json stringify with mixed-type variables and type assertions Mar 1, 2026
@cs01 cs01 merged commit a772535 into main Mar 1, 2026
12 checks passed
@cs01 cs01 deleted the worktree-fix-json-stringify-mixed-types branch March 1, 2026 17:27
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