diff --git a/scripts/test/dot-assignments-bugfix.toy b/scripts/test/dot-assignments-bugfix.toy new file mode 100644 index 0000000..341dbc7 --- /dev/null +++ b/scripts/test/dot-assignments-bugfix.toy @@ -0,0 +1,20 @@ +/* + +NOTES: For some reason, this code results in the error: + Undeclared variable "inner" + +It only occurs under these very specific conditions. + +It appears to be a compiler issue, see issue #38 for more info. + +*/ + +fn _getValue(self) { + return self; +} + +var cache; +cache = 42.getValue(); //assignment, rather than declaration, allows the bug + + +print "All good"; diff --git a/source/common.h b/source/common.h index 335007e..6cac89b 100644 --- a/source/common.h +++ b/source/common.h @@ -6,7 +6,7 @@ #define TOY_VERSION_MAJOR 0 #define TOY_VERSION_MINOR 6 -#define TOY_VERSION_PATCH 0 +#define TOY_VERSION_PATCH 1 #define TOY_VERSION_BUILD __DATE__ " " __TIME__ //platform exports/imports diff --git a/source/compiler.c b/source/compiler.c index 95421f4..d4537e7 100644 --- a/source/compiler.c +++ b/source/compiler.c @@ -333,7 +333,7 @@ static Opcode writeCompilerWithJumps(Compiler* compiler, ASTNode* node, void* br return node->binary.opcode; } - if (ret != OP_EOF && (node->binary.opcode == OP_AND || node->binary.opcode == OP_OR || (node->binary.opcode >= OP_COMPARE_EQUAL && node->binary.opcode <= OP_INVERT))) { + if (ret != OP_EOF && (node->binary.opcode == OP_VAR_ASSIGN || node->binary.opcode == OP_AND || node->binary.opcode == OP_OR || (node->binary.opcode >= OP_COMPARE_EQUAL && node->binary.opcode <= OP_INVERT))) { compiler->bytecode[compiler->count++] = (unsigned char)ret; //1 byte ret = OP_EOF; //untangle in this case } diff --git a/test/test_interpreter.c b/test/test_interpreter.c index 516ef5c..9d2f613 100644 --- a/test/test_interpreter.c +++ b/test/test_interpreter.c @@ -182,6 +182,7 @@ int main() { "coercions.toy", "comparisons.toy", "dot-and-matrix.toy", + "dot-assignments-bugfix.toy", "dot-chaining.toy", "functions.toy", "imports-and-exports.toy",