Skip to content

Commit f90bc00

Browse files
sailinglawlietlihongyuan
and
lihongyuan
authored
bugfix: parse expect error when mis match braces (#421)
* bugfix: parse expect error when mis match braces Change-Id: Iba1ad456d5b020375bb0416f44fb54bc2e346d62 * fix wrong test case in vm_test Change-Id: Idcdaf7ecc93eb61d374249d11282b8286557d30d --------- Co-authored-by: lihongyuan <lihongyuan.adrian@bytedance.com>
1 parent 82b543f commit f90bc00

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

parser/parser.go

+1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ func (p *Parser) ParseFile() (file *File, err error) {
143143
}
144144

145145
stmts := p.parseStmtList()
146+
p.expect(token.EOF)
146147
if p.errors.Len() > 0 {
147148
return nil, p.errors.Err()
148149
}

parser/parser_test.go

+14
Original file line numberDiff line numberDiff line change
@@ -1631,6 +1631,20 @@ func TestParseFloat(t *testing.T) {
16311631
}
16321632
}
16331633

1634+
func TestMismatchBrace(t *testing.T) {
1635+
expectParseError(t, `
1636+
fmt := import("fmt")
1637+
out := 0
1638+
if 3 == 1 {
1639+
out = 1
1640+
}
1641+
} else {
1642+
out = 2
1643+
}
1644+
fmt.println(out)
1645+
`)
1646+
}
1647+
16341648
func TestParseNumberExpressions(t *testing.T) {
16351649
expectParse(t, `0x15e+2`, func(p pfn) []Stmt {
16361650
return stmts(

vm_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -2754,10 +2754,10 @@ export func(a) {
27542754
Opts().Module("mod0", `if 1 { } else { export true }`),
27552755
tengo.UndefinedValue)
27562756
expectRun(t, `out = import("mod0")`,
2757-
Opts().Module("mod0", `for v:=0;;v++ { if v == 3 { export true } } }`),
2757+
Opts().Module("mod0", `for v:=0;;v++ { if v == 3 { export true } }`),
27582758
true)
27592759
expectRun(t, `out = import("mod0")`,
2760-
Opts().Module("mod0", `for v:=0;;v++ { if v == 3 { break } } }`),
2760+
Opts().Module("mod0", `for v:=0;;v++ { if v == 3 { break } }`),
27612761
tengo.UndefinedValue)
27622762

27632763
// duplicate compiled functions

0 commit comments

Comments
 (0)