Skip to content

Commit

Permalink
allow newline before dot for subscript as well, and add to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ruby0x1 committed Sep 20, 2020
1 parent 4c496c5 commit 3c475f0
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 45 deletions.
2 changes: 2 additions & 0 deletions src/vm/wren_compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -2378,6 +2378,8 @@ static void subscript(Compiler* compiler, bool canAssign)
finishArgumentList(compiler, &signature);
consume(compiler, TOKEN_RIGHT_BRACKET, "Expect ']' after arguments.");

allowLineBeforeDot(compiler);

if (canAssign && match(compiler, TOKEN_EQ))
{
signature.type = SIG_SUBSCRIPT_SETTER;
Expand Down
127 changes: 82 additions & 45 deletions test/language/chained_newline.wren
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ class Test {
System.print("test2")
return this
}

[index] {
System.print("testSubscript")
return this
}
}

class Tester {
Expand All @@ -22,36 +27,48 @@ class Tester {
//test local access

test.
test0(). // expect: test0
test1(). // expect: test1
test2() // expect: test2
test0(). // expect: test0
test1(). // expect: test1
test2() // expect: test2

test
.test0() // expect: test0
.test1() // expect: test1
.test2() // expect: test2
.test0() // expect: test0
.test1() // expect: test1
.test2() // expect: test2

test
.test0() // expect: test0
.test1(). // expect: test1
test2() // expect: test2
.test0() // expect: test0
.test1(). // expect: test1
test2() // expect: test2

test[0] // expect: testSubscript
.test0() // expect: test0

test[0]. // expect: testSubscript
test0() // expect: test0

//test field access

_test.
test0(). // expect: test0
test1(). // expect: test1
test2() // expect: test2
test0(). // expect: test0
test1(). // expect: test1
test2() // expect: test2

_test
.test0() // expect: test0
.test1() // expect: test1
.test2() // expect: test2
.test0() // expect: test0
.test1() // expect: test1
.test2() // expect: test2

_test
.test0(). // expect: test0
test1(). // expect: test1
test2() // expect: test2
.test0(). // expect: test0
test1(). // expect: test1
test2() // expect: test2

_test[0] // expect: testSubscript
.test0() // expect: test0

_test[0]. // expect: testSubscript
test0() // expect: test0

}

Expand All @@ -65,50 +82,70 @@ class Tester {
var external = Tester.new()

external.getter.
test0(). // expect: test0
test1(). // expect: test1
test2() // expect: test2
test0(). // expect: test0
test1(). // expect: test1
test2() // expect: test2

external.getter
.test0() // expect: test0
.test1() // expect: test1
.test2() // expect: test2
.test0() // expect: test0
.test1() // expect: test1
.test2() // expect: test2

external.getter.
test0() // expect: test0
.test1() // expect: test1
.test2() // expect: test2
test0() // expect: test0
.test1() // expect: test1
.test2() // expect: test2

external.getter[0]. // expect: testSubscript
test0() // expect: test0

external.getter[0] // expect: testSubscript
.test0() // expect: test0

external.method().
test0(). // expect: test0
test1(). // expect: test1
test2() // expect: test2
test0(). // expect: test0
test1(). // expect: test1
test2() // expect: test2

external.method()
.test0() // expect: test0
.test1() // expect: test1
.test2() // expect: test2
.test0() // expect: test0
.test1() // expect: test1
.test2() // expect: test2

external.method().
test0() // expect: test0
.test1(). // expect: test1
test2() // expect: test2
test0() // expect: test0
.test1(). // expect: test1
test2() // expect: test2

external.method()[0]. // expect: testSubscript
test0() // expect: test0

external.method()[0] // expect: testSubscript
.test0() // expect: test0


//regular access in module scope

var other = Test.new()

other.
test0(). // expect: test0
test1(). // expect: test1
test2() // expect: test2
test0(). // expect: test0
test1(). // expect: test1
test2() // expect: test2

other
.test0() // expect: test0
.test1() // expect: test1
.test2() // expect: test2
.test0() // expect: test0
.test1() // expect: test1
.test2() // expect: test2

other
.test0(). // expect: test0
test1() // expect: test1
.test2() // expect: test2
.test0(). // expect: test0
test1() // expect: test1
.test2() // expect: test2


other[0] // expect: testSubscript
.test0() // expect: test0

other[0]. // expect: testSubscript
test0() // expect: test0

0 comments on commit 3c475f0

Please sign in to comment.