Skip to content

Commit 7b0bab7

Browse files
committed
test: add test cases for lexical scoping edge cases
1 parent 082a837 commit 7b0bab7

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

test_programs/r4/3.lox

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
11
---
2-
expected_error_type: none
2+
expected_error_type: compile
33
---
4+
fun returnArg(arg) {
5+
return arg;
6+
}
7+
8+
var b = "global";
9+
10+
{
11+
var a = "first";
12+
var b = returnArg(b); // Using global 'b' in its initializer, but through a function call
13+
print b;
14+
}
15+
16+
// Reassigning with self-reference is fine for globals
17+
var b = b + " updated";
18+
print b;

test_programs/r4/4.lox

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
11
---
2-
expected_error_type: none
2+
expected_error_type: compile
33
---
4+
fun outer() {
5+
var a = "outer";
6+
7+
fun inner() {
8+
var a = a; // Error at 'a': Can't read local variable in its own initializer.
9+
print a;
10+
}
11+
12+
inner();
13+
}
14+
15+
outer();

0 commit comments

Comments
 (0)