Known Bugs
Every test in this folder fails on purpose. Each one reproduces a known bug, and its
.expected file holds the correct behavior, not the buggy output. These tests live outside
test_cases/ so the main suite (and CI) stays green while the bugs are being fixed.
All bugs were found against commit 77edefe. Line numbers refer to that commit.
Workflow
- Run a test directly to see the bug:
./cmake-build/Oli_Nat known_bugs/float_and_double_arithmetic.oli - Fix the bug in the VM.
- Run the test again and compare against its
.expected(and.exitcode, if it has one). - When it passes, move all of its files into
test_cases/regressions/. From then on CI
checks it on every push, so the bug can’t quietly come back. - Tick it off below.
Some bugs share a root cause, so fixing one can make several tests pass at once. Each
entry lists every test it affects.
Summary
| # | Bug | Severity | Tests |
|---|---|---|---|
| 1 | GC frees a new array before it is filled | 🔴 Crash | 1 |
| 2 | GC frees forward-declared function signatures | 🔴 Crash | 1 |
| 3 | Compiler hangs when error recovery reaches end of file | 🔴 Hang | 1 |
| 4 | Mixing float and double gives garbage | 🟠 Wrong result | 2 |
| 5 | Single \| or & acts as + | 🟠 Wrong result | 2 |
| 6 | Methods named like the class become constructors | 🟠 Wrong result | 2 |
| 7 | #pullf accepts library name prefixes | 🟡 Wrong result | 1 |
| 8 | Debug printf leaks onto stdout | 🟡 Wrong output | 2 |
| 9 | fileExists / deleteFile have the wrong return type | 🟡 Type error | 1 |
| 10 | Escaped quote ends a string early | 🟡 Compile error | 1 |
| 11 | Redeclaring a variable or parameter is allowed | 🟡 Missing check | 3 |
| 12 | Inner functions can’t call themselves | 🟡 Missing feature | 1 |
| 13 | Class-typed parameters and returns lose their class | 🟡 Missing feature | 2 |
| 14 | Calling a function above its definition | ⚪ Design decision | 1 |
| 15 | Test runner doesn’t feed stdin | ⚪ Runner, not VM | 1 |
🔴 Crashes and hangs
1. GC frees a new array before it is filled
- Fixed
Test: gc_frees_new_array_before_it_is_filled
Symptom: Creating many arrays in a loop aborts with free(): double free detected
(exit code -6).
Cause: newStaticArray (object.c:94) allocates the array object first, then calls
ALLOCATE for its values buffer. That second allocation can trigger a garbage collection.
The new array isn’t on the VM stack yet, so the GC thinks it’s garbage and sweeps it. Sweeping
calls free() on values, which was never initialized.
Fix: Allocate the values buffer before the object, or initialize the object
(values = NULL; length = 0;) and push it onto the stack before the second allocation, then
pop it afterwards. Crafting Interpreters uses the push/pop pattern for the same problem.
2. GC frees forward-declared function signatures
- Fixed
Test: forward_reference_signature_freed_by_gc
Symptom: Calling a function declared further down the file randomly fails with type
errors that don’t make sense, like “A return statement should match the type of its parent
function”. The old testCases(outdated)/weirdFunctionStuff/forward_declaration.txt segfaults.
Whether it breaks depends on when the GC happens to run, so it can look random.
Cause: In the first pass, declareFunction (ASTcompiler.c:1466) creates a placeholder
ObjFunction to hold the signature, stores a pointer to it in the type checker’s symbol
table, and then pops it off the VM stack (ASTcompiler.c:1519). After that nothing the GC
can see refers to it, so the next collection frees it, but the symbol table still points at
the freed memory. AddressSanitizer reports it as heap-use-after-free in checkExpression.
Fix: Either mark every function signature held by the type checker as a GC root during
compilation (walk the symbol table in markRoots), or store signatures in plain malloc’d
structs that the GC doesn’t own.
3. Compiler hangs when error recovery reaches end of file
- Fixed
Test: compiler_hangs_when_error_recovery_hits_eof
Symptom: A compile error near the end of a file (for example, a wrongly typed class
field as the last thing in the file) makes the compiler loop forever.
Cause: ASTcompiler.c:218 in synchronize:
while (!parser->current.type != T_EOF)!parser->current.type is always 0 or 1, which never equals T_EOF, so the loop never ends.
Fix: Remove the first !:
while (parser->current.type != T_EOF)🟠 Wrong results
4. Mixing float and double gives garbage
- Fixed
Tests: float_and_double_arithmetic, pow_with_float_and_double
Symptom: 1.5 + 2.5f prints 1075838977.500000. pow(2.0, 3.0f) prints inf.
Cause: In OP_ADD, OP_SUBTRACT, OP_MULTIPLY and OP_DIVIDE (vm.c:373–470), the
double branch converts the other operand with (double)GET_INT_VAL(x), assuming it’s an
int. When it’s a float, the float’s raw bits get read as an int. powNative
(natives.c:135) has the same pattern.
Fix: A small helper used in every branch avoids repeating this in eight places:
static double asDouble(Value v)
{
if (IS_DOUBLE(v)) return GET_DOUBLE_VAL(v);
if (IS_FLOAT(v)) return (double)GET_FLOAT_VAL(v);
return (double)GET_INT_VAL(v);
}5. Single | or & acts as +
- Fixed
Tests: single_pipe_is_not_addition, single_ampersand_is_not_addition
Symptom: println(2 | 3); prints 5 instead of failing to compile.
Cause: scanner.c:297–298. When the second character doesn’t match, there’s no return,
so the switch falls through into case '+'.
Fix: Return an error token when the match fails:
case '|': return match('|', scanner) ? makeToken(T_OR, scanner) : errorToken("Use '||' or 'or'.", scanner);
case '&': return match('&', scanner) ? makeToken(T_AND, scanner) : errorToken("Use '&&' or 'and'.", scanner);6. Methods named like the class become constructors
- Fixed
Tests: method_named_like_constructor_prefix, method_name_is_prefix_of_class_name
Symptom: In class Counter:
- a method called
CounterValue()is treated as the constructor, and calling it gives a
runtime error; - a method called
Count()returns the instance itself and printsINSTANCE-Counter.
Cause: Both checks use strncmp with only one of the two lengths, so they’re prefix
matches, not equality checks:
ASTcompiler.c:1350compares using the class name’s length;ASTcompiler.c:1025compares using the method name’s length.
Fix: Require equal lengths and equal characters:
nameLength == checker->currentClassNameLength &&
memcmp(name, checker->currentClassName, nameLength) == 0🟡 Smaller bugs
7. #pullf accepts library name prefixes
- Fixed
Test: library_name_prefix_is_accepted
Symptom: #pullf i imports io, and #pullf s imports stdlib.
Cause: strncmp(library, "io", length) with the source’s length is a prefix match.
This appears in both nativeFunction (ASTcompiler.c:1161) and the first pass
(ASTcompiler.c:1543).
Fix: Same idea as #6: check length == strlen("io") as well. A small
libraryIs(library, length, "io") helper keeps both places consistent.
8. Debug printf leaks onto stdout
- Fixed
Tests: undefined_parent_class_prints_debug_to_stdout, class_inheriting_from_itself
Symptom: Any undefined-global runtime error also prints Global not found: <name> to
stdout, mixed in with the program’s real output.
Cause: Leftover debug line at vm.c:703.
Fix: Delete it (runtimeError already reports the problem on stderr), or wrap it in
#ifdef DEBUG_TRACE_EXECUTION. Both tests should pass after this one change.
9. fileExists / deleteFile have the wrong return type
- Fixed
Test: file_exists_returns_bool
Symptom: make bool exists = fileExists(path); fails to compile with a type mismatch.
(println(fileExists(path)) only works because println accepts anything.)
Cause: typeChecker.c:159–160 registers both functions as returning VALUE_STRING.
At runtime fileExists returns a bool and deleteFile returns nothing.
Fix: Register fileExists as VALUE_BOOL and deleteFile as VALUE_EMPTY.
10. Escaped quote ends a string early
- Fixed
Test: escaped_quote_in_string
Symptom: println("say \"hi\""); fails to compile.
Cause: The parser’s string() in ASTcompiler.c already understands \", but the
scanner’s string() (scanner.c:77) stops at the first " it sees, escaped or not.
Fix: In the scanner loop, when you see a \, advance over the next character too:
if (peekChar(scanner) == '\\' && peekNextChar(scanner) != '\0') advance(scanner);11. Redeclaring a variable or parameter is allowed
- Fixed
Tests: redeclaring_a_variable_in_same_scope, redeclaring_a_global_with_new_type,
duplicate_parameter_names
Symptom: All of these compile:
{ make int x = 1; make int x = 2; }
make int value = 1; make string value = "now a string";
make int pick(int a, int a) { ... }The second one silently changes a variable’s type, which undermines the static type
system.
Fix: Before adding a symbol, search backwards through the symbols at the current scope
depth for the same name and raise an error if one exists. Apply the same check to parameters.
Shadowing in an inner scope should stay legal, and variables_and_scope/shadowing.oli
checks that it does.
12. Inner functions can’t call themselves
- Fixed
Test: inner_function_cannot_call_itself
Symptom: A function declared inside another function fails with
Global not found: sumTo when it calls itself.
Cause: The inner function’s local slot isn’t registered until after its body is
compiled. While the body compiles, its own name isn’t found as a local, so it’s compiled as a
global lookup, which doesn’t exist.
Fix: Declare the local and mark it initialized before compiling the function body.
Crafting Interpreters does this in funDeclaration with markInitialized().
13. Class-typed parameters and returns lose their class
- Fixed
Tests: class_typed_parameter_field_access, class_typed_return_value
Symptom: make empty heal(Player p) { p.health = 100; } fails with
Unknown class type. Declaring the parameter works, but accessing its fields doesn’t.
Cause: When a variable is declared with a class type, getVarDeclarationType stores
the class name in checker->lastClassName and the symbol remembers it. Parameters (and
return types) go through the same function, but the class name is never saved onto the
parameter’s symbol, so typeChecker.c:433 can’t find which class it belongs to.
Fix: Add a class-name field to ParamInfo, set it when the parameter’s type is
VALUE_INSTANCE, and copy it onto the local symbol when the parameter is declared. Do the same
for return types so calls to a function returning Vector have a known class.
⚪ Not exactly bugs
14. Calling a function above its definition
- Decided
Test: top_level_call_before_definition
Symptom: This passes the type checker but fails at runtime with
Undefined Global variable:
println(declaredLater(4));
make int declaredLater(int x) { return x * 2; }Cause: The first pass makes the type checker aware of every function up front, but the
function object only becomes a real global when execution reaches its declaration.
Decision needed: The README says the two-pass compiler makes forward references work.
Either keep that promise and hoist function definitions (emit all top-level function
definitions before the rest of the script), or have the checker reject top-level calls
to functions that haven’t been defined yet. The test currently expects hoisting (8). If you
choose the other option, change its .expected to empty and add an .exitcode of 70.
Calls from inside function bodies are a separate issue, covered by bug #2.
15. Test runner doesn’t feed stdin
- Fixed
Test: io_intake_reads_stdin
This isn’t a VM bug. The test comes with an io_intake_reads_stdin.stdin file holding
the input for intake(), but tools/bin/run_tests.py doesn’t pass it to the program yet.
Locally the program waits for keyboard input until it times out. In CI it gets no input and
the output doesn’t match.
Fix: In run_program, read source.with_suffix(".stdin") if it exists and pass its
contents to subprocess.run with input=. Once that works, move the test back to
test_cases/stdlib/.