File tree Expand file tree Collapse file tree 21 files changed +95
-129
lines changed
Expand file tree Collapse file tree 21 files changed +95
-129
lines changed Original file line number Diff line number Diff line change 11---
22expected_error_type: none
33---
4- // The closure should capture the global variable and declaring a local
5- // variable with the same name should not affect the closure's capture.
4+ // This variable is used in the function `f` below.
65var variable = "global";
6+
77{
88 fun f() {
99 print variable;
1010 }
1111
12- f(); // expect: global
12+ f(); // this should print "global"
13+
14+ // This variable declaration shouldn't affect the usage in `f` above.
1315 var variable = "local";
14- f(); // expect: global
16+
17+ f(); // this should still print "global"
1518}
Original file line number Diff line number Diff line change 1+ ---
2+ expected_error_type: none
3+ ---
4+ // Redeclaring a variable in the global scope should be allowed.
5+ var a = "value";
6+ var a = a; // global scope
7+ print a;
Original file line number Diff line number Diff line change 1+ ---
2+ expected_error_type: compile
3+ ---
4+ // A variable should not be able to be initialized with itself.
5+ var a = "outer";
6+ {
7+ var a = a; // Expect compile error.
8+ }
Original file line number Diff line number Diff line change 1+ ---
2+ expected_error_type: compile
3+ ---
4+ // A variable should not be able to be initialized with itself.
5+ fun returnArg(arg) {
6+ return arg;
7+ }
8+
9+ var b = "global";
10+
11+ {
12+ var a = "first";
13+ // Using global 'b' through a function call
14+ var b = returnArg(b); // Expect compile error.
15+ print b;
16+ }
17+
18+ // Reassigning with self-reference is fine for globals
19+ var b = b + " updated";
20+ print b;
Original file line number Diff line number Diff line change 1+ ---
2+ expected_error_type: compile
3+ ---
4+ // A variable should not be able to be initialized with itself.
5+ fun outer() {
6+ var a = "outer";
7+
8+ fun inner() {
9+ var a = a; // Error at 'a': Can't read local variable in its own initializer.
10+ print a;
11+ }
12+
13+ inner();
14+ }
15+
16+ outer();
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change 11---
2- expected_error_type: none
2+ expected_error_type: compile
33---
4- // Redeclaring a variable in the global scope should be allowed.
5- var a = "value";
6- var a = a; // global scope
7- print a;
4+ fun foo() {
5+ return "at function scope is ok";
6+ }
7+
8+ return; // Error: Can't return from top-level code.
You can’t perform that action at this time.
0 commit comments