From 52943bfe4d1a85e64e35a5c1173ce04ae2b98bb6 Mon Sep 17 00:00:00 2001
From: Russ Cox <rsc@golang.org>
Date: Tue, 22 Feb 2011 18:23:29 -0500
Subject: [PATCH] gc: require if condition

R=ken2, r2
CC=golang-dev
https://golang.org/cl/4195045
---
 src/cmd/gc/go.y   |  9 +++++++--
 test/syntax/if.go | 15 +++++++++++++++
 2 files changed, 22 insertions(+), 2 deletions(-)
 create mode 100644 test/syntax/if.go

diff --git a/src/cmd/gc/go.y b/src/cmd/gc/go.y
index 86e3cae33cc..4b838a49117 100644
--- a/src/cmd/gc/go.y
+++ b/src/cmd/gc/go.y
@@ -640,10 +640,15 @@ if_stmt:
 	{
 		markdcl();
 	}
-	if_header loop_body
+	if_header
+	{
+		if($3->ntest == N)
+			yyerror("missing condition in if statement");
+	}
+	loop_body
 	{
 		$$ = $3;
-		$$->nbody = $4;
+		$$->nbody = $5;
 		// no popdcl; maybe there's an LELSE
 	}
 
diff --git a/test/syntax/if.go b/test/syntax/if.go
new file mode 100644
index 00000000000..913d4188540
--- /dev/null
+++ b/test/syntax/if.go
@@ -0,0 +1,15 @@
+// errchk $G $D/$F.go
+
+// Copyright 2011 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+func main() {
+	if {  // ERROR "missing condition"
+	}
+	
+	if x(); {  // ERROR "missing condition"
+	}
+}
-- 
GitLab