Skip to content

Fix for #236 (__newindex implementation) - #325

Closed
Joy-less wants to merge 1 commit into
moonsharp-devs:legacy/2.0from
Joy-less:newindex-fix
Closed

Fix for #236 (__newindex implementation)#325
Joy-less wants to merge 1 commit into
moonsharp-devs:legacy/2.0from
Joy-less:newindex-fix

Conversation

@Joy-less

Copy link
Copy Markdown
Contributor
local MT = {}
function MT:__newindex(key, value)
  print('['..key..'] = '..value)
end
local T = {}
setmetatable(T, MT)
T.A, T.B, T.C = 1, 2, 3

Previously, this would output

[A] = 1
[B] = 2
[C] = nil

With the fix, it outputs

[A] = 1
[B] = 2
[C] = 3

(This is a somewhat surface-level fix, the cause of the issue is probably very deep-rooted)

@MaxHayman

Copy link
Copy Markdown
Member

Thanks for this, and for being straight about it being a surface level fix, you were right that the cause sits deeper.

I built it and ran it against a few extra cases. It does fix the one in your description, but two things still fall over.

Tuple r-values:

local function f() return 1, 2 end
T.A, T.B = f()   -- B is still nil

The restore is gated on value.Type == DataType.Void, but GetStoreValue hands back Nil rather than Void when tupleidx != 0 on a non-tuple, so the guard never fires and the value goes missing the same way.

And nested multiple assignment, a __newindex that itself does a multi-assign. The inner statement overwrites lastBurnedValueInIndexSet before the outer one gets to use it, so the outer's second target comes back Void and you're looking at the original "value expected" error again.

We might need to approach this from a different direction.

@MaxHayman

Copy link
Copy Markdown
Member

Fixed in cb4a978

@MaxHayman MaxHayman closed this Aug 2, 2026
@Joy-less
Joy-less deleted the newindex-fix branch August 2, 2026 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants