-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
93 changed files
with
1,848 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
if (true) "ok"; else class Foo {} | ||
// expect: line 1: location: at 'class': expected expression |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
if (true) class Foo {} | ||
// expect: line 1: location: at 'class': expected expression |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// A dangling else binds to the right-most if. | ||
if (true) if (false) print "bad"; else print "good"; // expect: good | ||
if (false) if (true) print "bad"; else print "bad"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Evaluate the 'else' expression if the condition is false. | ||
if (true) print "good"; else print "bad"; // expect: good | ||
if (false) print "bad"; else print "good"; // expect: good | ||
|
||
// Allow block body. | ||
if (false) nil; else { print "block"; } // expect: block |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
if (true) "ok"; else fun foo() {} | ||
// expect: line 1: location: at 'foo': expected '(' for function expression |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
if (true) fun foo() {} | ||
// expect: line 1: location: at 'foo': expected '(' for function expression |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Evaluate the 'then' expression if the condition is true. | ||
if (true) print "good"; // expect: good | ||
if (false) print "bad"; | ||
|
||
// Allow block body. | ||
if (true) { print "block"; } // expect: block | ||
|
||
// Assignment in if condition. | ||
var a = false; | ||
if (a = true) print a; // expect: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// False and nil are false. | ||
if (false) print "bad"; else print "false"; // expect: false | ||
if (nil) print "bad"; else print "nil"; // expect: nil | ||
|
||
// Everything else is true. | ||
if (true) print true; // expect: true | ||
if (0) print 0; // expect: 0 | ||
if ("") print "empty"; // expect: empty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
if (true) "ok"; else var foo; | ||
// expect: line 1: location: at 'var': expected expression |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
if (true) var foo; | ||
// expect: line 1: location: at 'var': expected expression |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class A { | ||
fun A(param) { | ||
this.field = param; | ||
} | ||
|
||
fun test() { | ||
print this.field; | ||
} | ||
} | ||
|
||
class B < A {} | ||
|
||
var b = B("value"); | ||
b.test(); | ||
// expect: line 13: location: at ')': expected 0 arguments, got 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
fun foo() {} | ||
|
||
class Subclass < foo {} | ||
// expect: line 3: location: at 'foo': expected class, got function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
var Nil = nil; | ||
class Foo < Nil {} | ||
// expect: line 2: location: at 'Nil': expected class, got nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
var Number = 123; | ||
class Foo < Number {} | ||
// expect: line 2: location: at 'Number': expected class, got number |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class Foo { | ||
fun methodOnFoo() { print "foo"; } | ||
fun override() { print "foo"; } | ||
} | ||
|
||
class Bar < Foo { | ||
fun methodOnBar() { print "bar"; } | ||
fun override() { print "bar"; } | ||
} | ||
|
||
var bar = Bar(); | ||
bar.methodOnFoo(); // expect: foo | ||
bar.methodOnBar(); // expect: bar | ||
bar.override(); // expect: bar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class Foo {} | ||
|
||
class Bar < (Foo) {} | ||
// expect: line 3: location: at '(': expected class name after '<' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
class Foo { | ||
fun foo(a, b) { | ||
this.field1 = a; | ||
this.field2 = b; | ||
} | ||
|
||
fun fooPrint() { | ||
print this.field1; | ||
print this.field2; | ||
} | ||
} | ||
|
||
class Bar < Foo { | ||
fun bar(a, b) { | ||
this.field1 = a; | ||
this.field2 = b; | ||
} | ||
|
||
fun barPrint() { | ||
print this.field1; | ||
print this.field2; | ||
} | ||
} | ||
|
||
var bar = Bar(); | ||
bar.foo("foo 1", "foo 2"); | ||
bar.fooPrint(); | ||
// expect: foo 1 | ||
// expect: foo 2 | ||
|
||
bar.bar("bar 1", "bar 2"); | ||
bar.barPrint(); | ||
// expect: bar 1 | ||
// expect: bar 2 | ||
|
||
bar.fooPrint(); | ||
// expect: bar 1 | ||
// expect: bar 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{} // By itself. | ||
|
||
// In a statement. | ||
if (true) {} | ||
if (false) {} else {} | ||
|
||
print "ok"; // expect: ok |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
var a = "outer"; | ||
|
||
{ | ||
var a = "inner"; | ||
print a; // expect: inner | ||
} | ||
|
||
print a; // expect: outer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Note: These tests implicitly depend on ints being truthy. | ||
|
||
// Return the first non-true argument. | ||
print false and 1; // expect: false | ||
print true and 1; // expect: 1 | ||
print 1 and 2 and false; // expect: false | ||
|
||
// Return the last argument if all are true. | ||
print 1 and true; // expect: true | ||
print 1 and 2 and 3; // expect: 3 | ||
|
||
// Short-circuit at the first false argument. | ||
var a = "before"; | ||
var b = "before"; | ||
(a = true) and | ||
(b = false) and | ||
(a = "bad"); | ||
print a; // expect: true | ||
print b; // expect: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// False and nil are false. | ||
print false and "bad"; // expect: false | ||
print nil and "bad"; // expect: nil | ||
|
||
// Everything else is true. | ||
print true and "ok"; // expect: ok | ||
print 0 and "ok"; // expect: ok | ||
print "" and "ok"; // expect: ok |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Note: These tests implicitly depend on ints being truthy. | ||
|
||
// Return the first true argument. | ||
print 1 or true; // expect: 1 | ||
print false or 1; // expect: 1 | ||
print false or false or true; // expect: true | ||
|
||
// Return the last argument if all are false. | ||
print false or false; // expect: false | ||
print false or false or false; // expect: false | ||
|
||
// Short-circuit at the first true argument. | ||
var a = "before"; | ||
var b = "before"; | ||
(a = false) or | ||
(b = true) or | ||
(a = "bad"); | ||
print a; // expect: false | ||
print b; // expect: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// False and nil are false. | ||
print false or "ok"; // expect: ok | ||
print nil or "ok"; // expect: ok | ||
|
||
// Everything else is true. | ||
print true or "ok"; // expect: true | ||
print 0 or "ok"; // expect: 0 | ||
print "s" or "ok"; // expect: s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class Foo { | ||
fun method0() { return "no args"; } | ||
fun method1(a) { return a; } | ||
fun method2(a, b) { return a + b; } | ||
fun method3(a, b, c) { return a + b + c; } | ||
fun method4(a, b, c, d) { return a + b + c + d; } | ||
fun method5(a, b, c, d, e) { return a + b + c + d + e; } | ||
fun method6(a, b, c, d, e, f) { return a + b + c + d + e + f; } | ||
fun method7(a, b, c, d, e, f, g) { return a + b + c + d + e + f + g; } | ||
fun method8(a, b, c, d, e, f, g, h) { return a + b + c + d + e + f + g + h; } | ||
} | ||
|
||
var foo = Foo(); | ||
print foo.method0(); // expect: no args | ||
print foo.method1(1); // expect: 1 | ||
print foo.method2(1, 2); // expect: 3 | ||
print foo.method3(1, 2, 3); // expect: 6 | ||
print foo.method4(1, 2, 3, 4); // expect: 10 | ||
print foo.method5(1, 2, 3, 4, 5); // expect: 15 | ||
print foo.method6(1, 2, 3, 4, 5, 6); // expect: 21 | ||
print foo.method7(1, 2, 3, 4, 5, 6, 7); // expect: 28 | ||
print foo.method8(1, 2, 3, 4, 5, 6, 7, 8); // expect: 36 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class Foo { | ||
fun bar() {} | ||
} | ||
|
||
print Foo().bar(); // expect: nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class Foo { | ||
fun method(a, b) { | ||
print a; | ||
print b; | ||
} | ||
} | ||
|
||
Foo().method(1, 2, 3, 4); | ||
// expect: line 8: location: at ')': expected 2 arguments, got 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class Foo { | ||
fun method(a, b) | ||
{a; b;} // suppress resolver | ||
} | ||
|
||
Foo().method(1); | ||
// expect: line 6: location: at ')': expected 2 arguments, got 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class Foo {} | ||
|
||
Foo().unknown(); | ||
// expect: line 3: location: at 'unknown': undefined property |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class Foo { | ||
fun method() { } | ||
} | ||
var foo = Foo(); | ||
print foo.method; // expect: function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class Foo { | ||
fun method() { | ||
// no 'this' | ||
print method; | ||
} | ||
} | ||
|
||
Foo().method(); | ||
// expect: line 4: location: at 'method': undeclared variable |
Oops, something went wrong.