Skip to content

Commit 3c475f0

Browse files
committed
allow newline before dot for subscript as well, and add to tests
1 parent 4c496c5 commit 3c475f0

File tree

2 files changed

+84
-45
lines changed

2 files changed

+84
-45
lines changed

src/vm/wren_compiler.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2378,6 +2378,8 @@ static void subscript(Compiler* compiler, bool canAssign)
23782378
finishArgumentList(compiler, &signature);
23792379
consume(compiler, TOKEN_RIGHT_BRACKET, "Expect ']' after arguments.");
23802380

2381+
allowLineBeforeDot(compiler);
2382+
23812383
if (canAssign && match(compiler, TOKEN_EQ))
23822384
{
23832385
signature.type = SIG_SUBSCRIPT_SETTER;

test/language/chained_newline.wren

Lines changed: 82 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ class Test {
1212
System.print("test2")
1313
return this
1414
}
15+
16+
[index] {
17+
System.print("testSubscript")
18+
return this
19+
}
1520
}
1621

1722
class Tester {
@@ -22,36 +27,48 @@ class Tester {
2227
//test local access
2328

2429
test.
25-
test0(). // expect: test0
26-
test1(). // expect: test1
27-
test2() // expect: test2
30+
test0(). // expect: test0
31+
test1(). // expect: test1
32+
test2() // expect: test2
2833

2934
test
30-
.test0() // expect: test0
31-
.test1() // expect: test1
32-
.test2() // expect: test2
35+
.test0() // expect: test0
36+
.test1() // expect: test1
37+
.test2() // expect: test2
3338

3439
test
35-
.test0() // expect: test0
36-
.test1(). // expect: test1
37-
test2() // expect: test2
40+
.test0() // expect: test0
41+
.test1(). // expect: test1
42+
test2() // expect: test2
43+
44+
test[0] // expect: testSubscript
45+
.test0() // expect: test0
46+
47+
test[0]. // expect: testSubscript
48+
test0() // expect: test0
3849

3950
//test field access
4051

4152
_test.
42-
test0(). // expect: test0
43-
test1(). // expect: test1
44-
test2() // expect: test2
53+
test0(). // expect: test0
54+
test1(). // expect: test1
55+
test2() // expect: test2
4556

4657
_test
47-
.test0() // expect: test0
48-
.test1() // expect: test1
49-
.test2() // expect: test2
58+
.test0() // expect: test0
59+
.test1() // expect: test1
60+
.test2() // expect: test2
5061

5162
_test
52-
.test0(). // expect: test0
53-
test1(). // expect: test1
54-
test2() // expect: test2
63+
.test0(). // expect: test0
64+
test1(). // expect: test1
65+
test2() // expect: test2
66+
67+
_test[0] // expect: testSubscript
68+
.test0() // expect: test0
69+
70+
_test[0]. // expect: testSubscript
71+
test0() // expect: test0
5572

5673
}
5774

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

6784
external.getter.
68-
test0(). // expect: test0
69-
test1(). // expect: test1
70-
test2() // expect: test2
85+
test0(). // expect: test0
86+
test1(). // expect: test1
87+
test2() // expect: test2
7188

7289
external.getter
73-
.test0() // expect: test0
74-
.test1() // expect: test1
75-
.test2() // expect: test2
90+
.test0() // expect: test0
91+
.test1() // expect: test1
92+
.test2() // expect: test2
7693

7794
external.getter.
78-
test0() // expect: test0
79-
.test1() // expect: test1
80-
.test2() // expect: test2
95+
test0() // expect: test0
96+
.test1() // expect: test1
97+
.test2() // expect: test2
98+
99+
external.getter[0]. // expect: testSubscript
100+
test0() // expect: test0
101+
102+
external.getter[0] // expect: testSubscript
103+
.test0() // expect: test0
81104

82105
external.method().
83-
test0(). // expect: test0
84-
test1(). // expect: test1
85-
test2() // expect: test2
106+
test0(). // expect: test0
107+
test1(). // expect: test1
108+
test2() // expect: test2
86109

87110
external.method()
88-
.test0() // expect: test0
89-
.test1() // expect: test1
90-
.test2() // expect: test2
111+
.test0() // expect: test0
112+
.test1() // expect: test1
113+
.test2() // expect: test2
91114

92115
external.method().
93-
test0() // expect: test0
94-
.test1(). // expect: test1
95-
test2() // expect: test2
116+
test0() // expect: test0
117+
.test1(). // expect: test1
118+
test2() // expect: test2
119+
120+
external.method()[0]. // expect: testSubscript
121+
test0() // expect: test0
122+
123+
external.method()[0] // expect: testSubscript
124+
.test0() // expect: test0
125+
96126

97127
//regular access in module scope
98128

99129
var other = Test.new()
100130

101131
other.
102-
test0(). // expect: test0
103-
test1(). // expect: test1
104-
test2() // expect: test2
132+
test0(). // expect: test0
133+
test1(). // expect: test1
134+
test2() // expect: test2
105135

106136
other
107-
.test0() // expect: test0
108-
.test1() // expect: test1
109-
.test2() // expect: test2
137+
.test0() // expect: test0
138+
.test1() // expect: test1
139+
.test2() // expect: test2
110140

111141
other
112-
.test0(). // expect: test0
113-
test1() // expect: test1
114-
.test2() // expect: test2
142+
.test0(). // expect: test0
143+
test1() // expect: test1
144+
.test2() // expect: test2
145+
146+
147+
other[0] // expect: testSubscript
148+
.test0() // expect: test0
149+
150+
other[0]. // expect: testSubscript
151+
test0() // expect: test0

0 commit comments

Comments
 (0)