Skip to content

runtime: parenthesized / as-cast assignment target silently mutates a const (no TypeError) #6300

Description

@proggeramlug

Summary

A parenthesized / as-cast assignment target bypasses the const immutability check entirely. The binding is mutated and no TypeError is thrown.

Repro

const c = 1;
(c as any) = 9;
console.log("const after cast-assign:", c);
result
node 26 TypeError: Assignment to constant variable.
perry main @ 0960415 prints const after cast-assign: 9

Verified on a clean origin/main build.

Why it matters

The const-binding immutability check is attached only to the bare-identifier assignment path; wrapping the LHS in parentheses or a TS cast routes around it. This is a silent wrong answer — a const is observably mutated with no diagnostic.

Related: #3571 (strict-mode unresolvable assignment / lexical declaration errors) covers the same area, but its other cases now pass; this one does not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugConfirmed defect or regression

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions