]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: don't crash on complex(0())
authorJosh Bleecher Snyder <josharian@gmail.com>
Sun, 11 Sep 2016 19:16:11 +0000 (12:16 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Sun, 11 Sep 2016 20:43:51 +0000 (20:43 +0000)
Fixes #17038.

Change-Id: Iaf6294361050040830af1d60cd48f263223d9356
Reviewed-on: https://go-review.googlesource.com/28966
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/cmd/compile/internal/gc/typecheck.go
test/fixedbugs/issue17038.go [new file with mode: 0644]

index f5a244e85f6ef94a5d46fd9e7e89abc430b52e91..68b0fd8e560d55422d02ed8156528d83543442ab 100644 (file)
@@ -1397,6 +1397,10 @@ OpSwitch:
                        }
 
                        t := n.List.First().Left.Type
+                       if !t.IsKind(TFUNC) {
+                               // Bail. This error will be reported elsewhere.
+                               return n
+                       }
                        if t.Results().NumFields() != 2 {
                                Yyerror("invalid operation: complex expects two arguments, %v returns %d results", n.List.First(), t.Results().NumFields())
                                n.Type = nil
diff --git a/test/fixedbugs/issue17038.go b/test/fixedbugs/issue17038.go
new file mode 100644 (file)
index 0000000..1b65ffc
--- /dev/null
@@ -0,0 +1,9 @@
+// errorcheck
+
+// Copyright 2016 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
+
+const A = complex(0()) // ERROR "cannot call non-function"