diff --git a/parser/_testdata/cmdlinestyle5/cmd5.gop b/parser/_testdata/cmdlinestyle5/cmd5.gop new file mode 100644 index 000000000..f6d42c61a --- /dev/null +++ b/parser/_testdata/cmdlinestyle5/cmd5.gop @@ -0,0 +1 @@ +println (1+2i)*2 diff --git a/parser/_testdata/cmdlinestyle5/parser.expect b/parser/_testdata/cmdlinestyle5/parser.expect new file mode 100644 index 000000000..ef36cabbb --- /dev/null +++ b/parser/_testdata/cmdlinestyle5/parser.expect @@ -0,0 +1,41 @@ +package main + +file cmd5.gop +noEntrypoint +ast.FuncDecl: + Name: + ast.Ident: + Name: main + Type: + ast.FuncType: + Params: + ast.FieldList: + Body: + ast.BlockStmt: + List: + ast.ExprStmt: + X: + ast.CallExpr: + Fun: + ast.Ident: + Name: println + Args: + ast.BinaryExpr: + X: + ast.ParenExpr: + X: + ast.BinaryExpr: + X: + ast.BasicLit: + Kind: INT + Value: 1 + Op: + + Y: + ast.BasicLit: + Kind: IMAG + Value: 2i + Op: * + Y: + ast.BasicLit: + Kind: INT + Value: 2 diff --git a/parser/parser.go b/parser/parser.go index 264a601d5..aeb337604 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -1896,7 +1896,8 @@ L: if lhs { p.resolve(x) } - x = p.parseCallOrConversion(p.checkExprOrType(x), false) + isCmd := allowCmd && x.End() != p.pos // println () + x = p.parseCallOrConversion(p.checkExprOrType(x), isCmd) case token.LBRACE: // { if allowCmd && x.End() != p.pos { // println {} x = p.parseCallOrConversion(p.checkExprOrType(x), true)