File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -297,6 +297,36 @@ func TestTraitMethodLookup(t *testing.T) {
297297 ` ,
298298 expected : 30 ,
299299 },
300+ {
301+ name : "comma-separated traits" ,
302+ input : `
303+ trait First {
304+ function first() {
305+ return 1
306+ }
307+ }
308+
309+ trait Second {
310+ function second() {
311+ return 2
312+ }
313+ }
314+
315+ trait Third {
316+ function third() {
317+ return 3
318+ }
319+ }
320+
321+ class Thing {
322+ use First, Second, Third
323+ }
324+
325+ t = Thing.new()
326+ t.first() + t.second() + t.third()
327+ ` ,
328+ expected : 6 ,
329+ },
300330 }
301331
302332 for _ , tt := range tests {
Original file line number Diff line number Diff line change @@ -13,8 +13,19 @@ func (parser *Parser) useExpression() ast.ExpressionNode {
1313 }
1414
1515 identifier := & ast.Identifier {Token : parser .currentToken , Value : parser .currentToken .Lexeme }
16-
1716 use .Traits = append (use .Traits , identifier )
1817
18+ for parser .nextTokenIs (token .COMMA ) {
19+ parser .readToken () // consume comma
20+
21+ if ! parser .expectNextTokenIs (token .IDENTIFIER ) {
22+ return nil
23+ }
24+
25+ identifier := & ast.Identifier {Token : parser .currentToken , Value : parser .currentToken .Lexeme }
26+
27+ use .Traits = append (use .Traits , identifier )
28+ }
29+
1930 return use
2031}
You can’t perform that action at this time.
0 commit comments