From 1fe4c81282f22b5ac9ba25e7972109255e173b04 Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Sun, 11 Sep 2016 12:16:11 -0700 Subject: [PATCH] cmd/compile: don't crash on complex(0()) Fixes #17038. Change-Id: Iaf6294361050040830af1d60cd48f263223d9356 Reviewed-on: https://go-review.googlesource.com/28966 Run-TryBot: Josh Bleecher Snyder TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/cmd/compile/internal/gc/typecheck.go | 4 ++++ test/fixedbugs/issue17038.go | 9 +++++++++ 2 files changed, 13 insertions(+) create mode 100644 test/fixedbugs/issue17038.go diff --git a/src/cmd/compile/internal/gc/typecheck.go b/src/cmd/compile/internal/gc/typecheck.go index f5a244e85f..68b0fd8e56 100644 --- a/src/cmd/compile/internal/gc/typecheck.go +++ b/src/cmd/compile/internal/gc/typecheck.go @@ -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 index 0000000000..1b65ffc1f0 --- /dev/null +++ b/test/fixedbugs/issue17038.go @@ -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" -- 2.48.1