Fixed the way an identifier was handled, resolved #99

This commit is contained in:
2023-08-04 14:45:07 +10:00
parent 967963c9d7
commit 67e49b7477

View File

@@ -582,7 +582,7 @@ static bool execVarDecl(Toy_Interpreter* interpreter, bool lng) {
typeIndex = (int)readByte(interpreter->bytecode, &interpreter->count); typeIndex = (int)readByte(interpreter->bytecode, &interpreter->count);
} }
Toy_Literal identifier = interpreter->literalCache.literals[identifierIndex]; Toy_Literal identifier = Toy_copyLiteral(interpreter->literalCache.literals[identifierIndex]);
Toy_Literal type = Toy_copyLiteral(interpreter->literalCache.literals[typeIndex]); Toy_Literal type = Toy_copyLiteral(interpreter->literalCache.literals[typeIndex]);
Toy_Literal typeIdn = type; Toy_Literal typeIdn = type;
@@ -597,6 +597,10 @@ static bool execVarDecl(Toy_Interpreter* interpreter, bool lng) {
interpreter->errorOutput("Can't redefine the variable \""); interpreter->errorOutput("Can't redefine the variable \"");
Toy_printLiteralCustom(identifier, interpreter->errorOutput); Toy_printLiteralCustom(identifier, interpreter->errorOutput);
interpreter->errorOutput("\"\n"); interpreter->errorOutput("\"\n");
Toy_freeLiteral(identifier);
Toy_freeLiteral(type);
return false; return false;
} }
@@ -623,14 +627,16 @@ static bool execVarDecl(Toy_Interpreter* interpreter, bool lng) {
Toy_printLiteralCustom(identifier, interpreter->errorOutput); Toy_printLiteralCustom(identifier, interpreter->errorOutput);
interpreter->errorOutput("\"\n"); interpreter->errorOutput("\"\n");
Toy_freeLiteral(identifier);
Toy_freeLiteral(type); Toy_freeLiteral(type);
Toy_freeLiteral(val); Toy_freeLiteral(val);
return false; return false;
} }
Toy_freeLiteral(val); Toy_freeLiteral(identifier);
Toy_freeLiteral(type); Toy_freeLiteral(type);
Toy_freeLiteral(val);
return true; return true;
} }