Skip to content

fix: emit compile error for for...of on numeric maps instead of segfaulting#200

Merged
cs01 merged 1 commit intomainfrom
fix/map-forof-numeric-guard
Mar 11, 2026
Merged

fix: emit compile error for for...of on numeric maps instead of segfaulting#200
cs01 merged 1 commit intomainfrom
fix/map-forof-numeric-guard

Conversation

@cs01
Copy link
Copy Markdown
Owner

@cs01 cs01 commented Mar 11, 2026

Problem

for (const [k, v] of numericMap) on a Map<number, number> silently generated wrong code — it called stringMapGen.generateStringMapEntries on a %Map struct (which has double* arrays, not i8**). The destructured values were treated as i8* string pointers, so any use of k or v (e.g. console.log(k)) caused a segfault.

Fix

Added a guard in generateMapEntriesForOf that checks map metadata before generating entries iteration. If the map has no metadata (numeric maps don't store mapMetadata) or the key type isn't "string", the compiler now emits a clear compile error:

file.ts:6:3: error: for...of on Map<number, *> is not supported — use Map<string, *> instead

This is consistent with method-calls.ts which already emits compile errors for numericMap.entries(), numericMap.keys(), and numericMap.values().

Test plan

  • New test fixture: map-numeric-entries-error.ts (expects compile error)
  • All 459 tests pass

@cs01 cs01 merged commit 960dfb3 into main Mar 11, 2026
12 checks passed
@cs01 cs01 deleted the fix/map-forof-numeric-guard branch March 11, 2026 01:09
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