Skip to content

Commit

Permalink
Make parenthesis required in new expressions.
Browse files Browse the repository at this point in the history
  • Loading branch information
skinny85 committed Aug 21, 2023
1 parent 26d4711 commit 0e1fab3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ expr4 : left=expr4 o=('+' | '-') right=expr5 #AddSubtractExpr4
expr5 : literal #LiteralExpr5
| ID #ReferenceExpr5
| expr5 '.' ID #PropertyReadExpr5
| 'new' constr=expr5 ('('(expr1 (',' expr1)*)?')')? #NewExpr5
| 'new' constr=expr5 '(' (expr1 (',' expr1)*)? ')' #NewExpr5
| '[' (expr1 (',' expr1)*)? ']' #ArrayLiteralExpr5
| arr=expr5 '[' index=expr1 ']' #ArrayIndexReadExpr5
| expr5 '(' (expr1 (',' expr1)*)? ')' #CallExpr5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void class_can_be_instantiated() {
" return 'A.a'; " +
" } " +
"} " +
"new A;");
"new A();");

assertTrue(result.hasMembers());
assertTrue(result.hasMember("a"));
Expand All @@ -51,11 +51,25 @@ void class_can_be_instantiated() {
assertEquals("A.a", methodA.execute().asString());
}

@Test
void methods_can_be_called_on_class_instances() {
Value result = this.context.eval("ezs", "" +
"class A { " +
" a() { " +
" return 'A.a'; " +
" } " +
"} " +
"const a = new A(); " +
"a.a(); ");

assertEquals("A.a", result.asString());
}

@Test
void new_with_non_class_is_an_error() {
try {
this.context.eval("ezs",
"new 3;");
"new 3();");
fail("expected PolyglotException to be thrown");
} catch (PolyglotException e) {
assertTrue(e.isGuestException());
Expand Down

0 comments on commit 0e1fab3

Please sign in to comment.