Skip to content

[sema] reject inline as { ... } on opaque source types#748

Merged
cs01 merged 2 commits intomainfrom
sema/opaque-cast-v2
Apr 26, 2026
Merged

[sema] reject inline as { ... } on opaque source types#748
cs01 merged 2 commits intomainfrom
sema/opaque-cast-v2

Conversation

@cs01
Copy link
Copy Markdown
Owner

@cs01 cs01 commented Apr 26, 2026

Before

(x as unknown as { type: string; value: number }) silently passed the type-assertion prefix checker because there's no source interface to compare against. In native code, the inline fields become GEP indices — if they don't match the actual struct layout, it reads wrong memory.

After

Compile error when an inline as { ... } assertion (2+ fields) follows an as unknown, as any, or as object intermediate cast. Suggests using as NamedInterface instead.

Description

Extends type-assertion-checker.ts with a new checkOpaqueSource method. This was the last unaccounted-for hazard in the "Patterns That Crash" list — inline as { ... } on opaque-typed sources where the prefix checker has nothing to verify against. ~30 LOC.

Closes item #3 from #729. Replaces #747 which was closed without merge due to stale CI check status.

Next Steps

@cs01 cs01 merged commit 453c8ec into main Apr 26, 2026
9 checks passed
@cs01 cs01 deleted the sema/opaque-cast-v2 branch April 26, 2026 19:23
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