aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/go/parser/parser.go6
-rw-r--r--src/go/types/testdata/issues.src8
2 files changed, 14 insertions, 0 deletions
diff --git a/src/go/parser/parser.go b/src/go/parser/parser.go
index 7671d2a4bb..189bfb4223 100644
--- a/src/go/parser/parser.go
+++ b/src/go/parser/parser.go
@@ -1830,6 +1830,7 @@ func (p *parser) makeExpr(s ast.Stmt, want string) ast.Expr {
func (p *parser) parseIfHeader() (init ast.Stmt, cond ast.Expr) {
if p.tok == token.LBRACE {
p.error(p.pos, "missing condition in if statement")
+ cond = &ast.BadExpr{From: p.pos, To: p.pos}
return
}
// p.tok != token.LBRACE
@@ -1877,6 +1878,11 @@ func (p *parser) parseIfHeader() (init ast.Stmt, cond ast.Expr) {
}
}
+ // make sure we have a valid AST
+ if cond == nil {
+ cond = &ast.BadExpr{From: p.pos, To: p.pos}
+ }
+
p.exprLev = outer
return
}
diff --git a/src/go/types/testdata/issues.src b/src/go/types/testdata/issues.src
index 8c11b376c8..da6dc6320a 100644
--- a/src/go/types/testdata/issues.src
+++ b/src/go/types/testdata/issues.src
@@ -240,3 +240,11 @@ func issue24140(x interface{}) int {
panic(0)
}
}
+
+// Test that we don't crash when the 'if' condition is missing.
+func issue25438() {
+ if { /* ERROR missing condition */ }
+ if x := 0; /* ERROR missing condition */ { _ = x }
+ if
+ { /* ERROR missing condition */ }
+}