]> Cypherpunks repositories - gostls13.git/commitdiff
gc: require if condition
authorRuss Cox <rsc@golang.org>
Tue, 22 Feb 2011 23:23:29 +0000 (18:23 -0500)
committerRuss Cox <rsc@golang.org>
Tue, 22 Feb 2011 23:23:29 +0000 (18:23 -0500)
R=ken2, r2
CC=golang-dev
https://golang.org/cl/4195045

src/cmd/gc/go.y
test/syntax/if.go [new file with mode: 0644]

index 86e3cae33ccbc68c643f6762244f927dfabe3495..4b838a491175863b2f7e92ecf672ff0a5ce46096 100644 (file)
@@ -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 (file)
index 0000000..913d418
--- /dev/null
@@ -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"
+       }
+}