Nesting index multiplication assignment fixed

This affects all arithmetic types applied to inner-nested compounds.
This commit is contained in:
2023-02-05 06:28:18 +00:00
parent 386201b6e9
commit 7b26527e95
3 changed files with 12 additions and 7 deletions

View File

@@ -1,9 +1,6 @@
var a = [[1, 2, 3], [4, 5, 6], [7, 8, 9]];
var d = ["foo" : ["bar" : ["bazz": ["fizz" : 5]]]];
a[1][1] *= 10;
print d;
d["foo"]["bar"]["bazz"]["fizz"] = 66;
print d;
print a;

View File

@@ -312,7 +312,7 @@ static Toy_Opcode Toy_writeCompilerWithJumps(Toy_Compiler* compiler, Toy_ASTNode
//return this if...
Toy_Opcode ret = Toy_writeCompilerWithJumps(compiler, node->binary.right, breakAddressesPtr, continueAddressesPtr, jumpOffsets, rootNode);
if (node->binary.opcode == TOY_OP_INDEX && rootNode->type == TOY_AST_NODE_BINARY && rootNode->binary.opcode == TOY_OP_VAR_ASSIGN) { //why var assign?
if (node->binary.opcode == TOY_OP_INDEX && rootNode->type == TOY_AST_NODE_BINARY && (rootNode->binary.opcode >= TOY_OP_VAR_ASSIGN && rootNode->binary.opcode <= TOY_OP_VAR_MODULO_ASSIGN)) { //range-based check for assignment type
return TOY_OP_INDEX_ASSIGN_INTERMEDIATE;
}

View File

@@ -71,6 +71,14 @@
assert a[0][0] == [42], "nested indexing failed";
}
//test nested indexing multipliciation assignment
{
var a = [[1, 2, 3], [4, 5, 6], [7, 8, 9]];
a[1][1] *= 10;
assert a == [[1, 2, 3], [4, 50, 6], [7, 8, 9]], "nested indexing multipliciation assignment failed";
}
//test combine example
{