Skip to content

fix: strict type resolution — eliminate silent default-to-double/i8*#160

Merged
cs01 merged 2 commits intomainfrom
fix/replace-inline-type-assertions-with-named-types
Mar 9, 2026
Merged

fix: strict type resolution — eliminate silent default-to-double/i8*#160
cs01 merged 2 commits intomainfrom
fix/replace-inline-type-assertions-with-named-types

Conversation

@cs01
Copy link
Copy Markdown
Owner

@cs01 cs01 commented Mar 9, 2026

Summary

  • Replace silent return "double" defaults in fieldToLlvmType() (class.ts) with explicit throw Error — null fields and unrecognized types no longer silently become numbers
  • Replace silent return "double" in getScopeVarType() (closure-analyzer.ts) — missing closure variables now error
  • Add explicit handling in canonicalTypeToLlvm() for any, never, void, object, function types (=>), inline object types ({...}), already-resolved LLVM types, and uppercase class/interface names
  • Fix LLVM-type-as-tsType bug in member.ts:1719 — was passing "i8*" LLVM type to a TS→LLVM conversion function
  • Fix for...of on string codegen bug — ChadScript treats string char iteration as double array, use index loop instead

Native compiler corruption discovery

  • The old catch-all return "i8*" in canonicalTypeToLlvm was silently masking 294 corrupted type strings per Stage 1 build
  • Root cause identified: 93 inline as { name: string; type: string } assertions on InterfaceField elements across 17 codegen files
  • The native compiler can't determine struct layout from anonymous assertions, falls back to csyyjson_obj_get which reads garbage memory
  • Fix: replace all inline assertions with named InterfaceField type from ast/types.ts (separate PR)
  • Catch-all return "i8*" kept for now with clear TODO comment documenting root cause

Test plan

  • 437 tests pass
  • verify:quick passes (tsc + Stage 0 + Stage 1)
  • macOS CI passes

@cs01 cs01 force-pushed the fix/replace-inline-type-assertions-with-named-types branch from 5b72577 to 3331993 Compare March 9, 2026 21:19
@cs01 cs01 force-pushed the fix/replace-inline-type-assertions-with-named-types branch from 3331993 to 97e1e0d Compare March 9, 2026 21:32
@cs01 cs01 merged commit ecf2c6b into main Mar 9, 2026
12 checks passed
@cs01 cs01 deleted the fix/replace-inline-type-assertions-with-named-types branch March 12, 2026 05:35
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