From d62c6c3c39ddc59e3003304f98661598b5fd80de Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Thu, 4 May 2017 11:43:41 -0700 Subject: [PATCH] cmd/compile: suppress duplicate type errors If we've already complained about a type T, don't complain again about further expressions involving it. Fixes #20245 and hopefully all of its ilk. Change-Id: Ic0abe8235d52e8a7ac40e3615aea8f3a54fd7cec Reviewed-on: https://go-review.googlesource.com/42690 Run-TryBot: Josh Bleecher Snyder TryBot-Result: Gobot Gobot Reviewed-by: Robert Griesemer --- src/cmd/compile/internal/gc/typecheck.go | 4 +++- test/fixedbugs/issue11614.go | 2 +- test/fixedbugs/issue20233.go | 2 +- test/fixedbugs/issue20245.go | 11 +++++++++++ 4 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 test/fixedbugs/issue20245.go diff --git a/src/cmd/compile/internal/gc/typecheck.go b/src/cmd/compile/internal/gc/typecheck.go index e66ce5dc985..6f544a5b9ae 100644 --- a/src/cmd/compile/internal/gc/typecheck.go +++ b/src/cmd/compile/internal/gc/typecheck.go @@ -2156,7 +2156,9 @@ OpSwitch: evconst(n) if n.Op == OTYPE && top&Etype == 0 { - yyerror("type %v is not an expression", n.Type) + if !n.Type.Broke() { + yyerror("type %v is not an expression", n.Type) + } n.Type = nil return n } diff --git a/test/fixedbugs/issue11614.go b/test/fixedbugs/issue11614.go index 959643a5147..91f134d44a9 100644 --- a/test/fixedbugs/issue11614.go +++ b/test/fixedbugs/issue11614.go @@ -15,7 +15,7 @@ type I interface { } func n() { - (I) // ERROR "type I is not an expression" + (I) } func m() { diff --git a/test/fixedbugs/issue20233.go b/test/fixedbugs/issue20233.go index 5734cf44ef0..4dec4e458be 100644 --- a/test/fixedbugs/issue20233.go +++ b/test/fixedbugs/issue20233.go @@ -8,4 +8,4 @@ package p -var f = func(...A) // ERROR "type func(....*) is not an expression" ERROR "undefined: A" +var f = func(...A) // ERROR "undefined: A" diff --git a/test/fixedbugs/issue20245.go b/test/fixedbugs/issue20245.go new file mode 100644 index 00000000000..b07dbe20de6 --- /dev/null +++ b/test/fixedbugs/issue20245.go @@ -0,0 +1,11 @@ +// errorcheck + +// Copyright 2017 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. + +// Issue 20245: panic while formatting an error message + +package p + +var e = interface{ I1 } // ERROR "undefined: I1"