Skip to content

Commit

Permalink
Merge pull request #1395 from visualfc/classfile_var
Browse files Browse the repository at this point in the history
parser: check token var
  • Loading branch information
xushiwei authored Jul 24, 2023
2 parents 74fdb39 + e6a4ad9 commit 013d54e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -3356,7 +3356,7 @@ func (p *parser) parseValueSpec(doc *ast.CommentGroup, keyword token.Token, iota
var typ ast.Expr
var tag *ast.BasicLit
var values []ast.Expr
if p.mode&ParseGoPlusClass != 0 && p.topScope == p.pkgScope && p.varDeclCnt == 1 {
if p.mode&ParseGoPlusClass != 0 && p.topScope == p.pkgScope && keyword == token.VAR && p.varDeclCnt == 1 {
var starPos token.Pos
if p.tok == token.MUL {
starPos = p.pos
Expand Down
6 changes: 6 additions & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,12 @@ func TestClassErrCode(t *testing.T) {
v = 10
)
`, `/foo/bar.gopx:2:4: syntax error: cannot assign value to field in class file`, ``)
testClassErrCode(t, `
var (
)
const c = 100
const d
`, `/foo/bar.gopx:5:7: missing constant value`, ``)
}

// -----------------------------------------------------------------------------

0 comments on commit 013d54e

Please sign in to comment.