Skip to content

Commit 1c8c9e6

Browse files
authored
Fix string literal slicing error (#543)
1 parent 564b637 commit 1c8c9e6

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

expr_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,6 +1180,10 @@ func TestExpr(t *testing.T) {
11801180
`bitushr(-100, 5)`,
11811181
576460752303423484,
11821182
},
1183+
{
1184+
`"hello"[1:3]`,
1185+
"el",
1186+
},
11831187
}
11841188

11851189
for _, tt := range tests {

parser/parser.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,8 @@ func (p *parser) parseSecondary() Node {
369369
return node
370370
case String:
371371
p.next()
372-
node := &StringNode{Value: token.Value}
372+
node = &StringNode{Value: token.Value}
373373
node.SetLocation(token.Location)
374-
return node
375374

376375
default:
377376
if token.Is(Bracket, "[") {

parser/parser_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,14 @@ world`},
523523
Property: &IntegerNode{Value: 0},
524524
},
525525
},
526+
{
527+
`"hello"[1:3]`,
528+
&SliceNode{
529+
Node: &StringNode{Value: "hello"},
530+
From: &IntegerNode{Value: 1},
531+
To: &IntegerNode{Value: 3},
532+
},
533+
},
526534
}
527535
for _, test := range tests {
528536
t.Run(test.input, func(t *testing.T) {

0 commit comments

Comments
 (0)