Skip to content

Fix table properties being inferred as readonly with compound assignment - #2724

Open
Companion wants to merge 2 commits into
luau-lang:masterfrom
Companion:fix/compound-assignment-property-inference
Open

Fix table properties being inferred as readonly with compound assignment#2724
Companion wants to merge 2 commits into
luau-lang:masterfrom
Companion:fix/compound-assignment-property-inference

Conversation

@Companion

@Companion Companion commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Problem

Compound assignment does not record that its target property is being written to during constraint generation.

For example:

local function f(x)
    x.h += 1
    return x.h > 2
end

incorrectly reports:

Property h of table '{ read h: number }' is read only

The equivalent ordinary assignment, x.h = x.h + 1, succeeds and infers the property as read write.

Change

Record property writes performed by compound assignments allowing inferred properties to become read write in the same way as ordinary assignments.

The change is limited to property and index expression targets. Locals and globals remain excluded because compound assignment must not update their typestate.

Because a compound assignment uses the same AST expression for both reading and writing its target the existing read type is preserved while the write constraint is recorded. Genuine read only and write only property violations continue to be reported.

Fixes #2603.

Testing

Added coverage for:

  • Inferring a read write property through compound assignment
  • Matching ordinary and compound assignment inference
  • Compound assignment with another arithmetic operator
  • Compound assignment through an index expression
  • Existing mutable properties
  • Preserving local variable typestate
  • Rejecting writes to read only properties
  • Rejecting reads from write only properties
  • Rejecting writes through read only indexers

The positive regression tests were verified to be load bearing by temporarily neutralizing only the new write recording path.

@Companion
Companion requested a review from a team as a code owner August 30, 2026 01:02
@Companion
Companion requested a review from SPY August 30, 2026 01:02
@Companion Companion closed this Aug 30, 2026
@Companion Companion reopened this Aug 30, 2026
@Companion
Companion force-pushed the fix/compound-assignment-property-inference branch from 323a28a to bbe0826 Compare August 30, 2026 01:07
Comment thread Analysis/src/ConstraintGenerator.cpp Outdated
Comment thread Analysis/src/ConstraintGenerator.cpp
Inline compound assignment property check

Co-authored-by: ariel <aweiss@hey.com>
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.

Table field is inferred as read-only when compound assignment is used instead of standard assignment

2 participants