From: Josh Bleecher Snyder Date: Mon, 10 Apr 2017 19:42:52 +0000 (-0700) Subject: cmd/compile: make iface == iface const evaluation respect != X-Git-Tag: go1.9beta1~759 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=b83a916f7186eb98636407c304974db34277aa2f;p=gostls13.git cmd/compile: make iface == iface const evaluation respect != Fixes #19911 Change-Id: Ib2b2505fe31ce00c6ffc021a0fe5df510633b44b Reviewed-on: https://go-review.googlesource.com/40251 Run-TryBot: Josh Bleecher Snyder TryBot-Result: Gobot Gobot Reviewed-by: Matthew Dempsky --- diff --git a/src/cmd/compile/internal/gc/const.go b/src/cmd/compile/internal/gc/const.go index 3826b69157..9747f13de3 100644 --- a/src/cmd/compile/internal/gc/const.go +++ b/src/cmd/compile/internal/gc/const.go @@ -815,6 +815,9 @@ func evconst(n *Node) { // check for compatible general types (numeric, string, etc) if wl != wr { if wl == TINTER || wr == TINTER { + if n.Op == ONE { + goto settrue + } goto setfalse } goto illegal diff --git a/test/fixedbugs/issue19911.go b/test/fixedbugs/issue19911.go new file mode 100644 index 0000000000..af7f59814e --- /dev/null +++ b/test/fixedbugs/issue19911.go @@ -0,0 +1,34 @@ +// run + +// 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. + +package main + +import ( + "fmt" + "strings" +) + +type ET struct{} + +func (*ET) Error() string { return "err" } + +func main() { + check("false", fmt.Sprintf("(*ET)(nil) == error(nil): %v", (*ET)(nil) == error(nil))) + check("true", fmt.Sprintf("(*ET)(nil) != error(nil): %v", (*ET)(nil) != error(nil))) + + nilET := (*ET)(nil) + nilError := error(nil) + + check("false", fmt.Sprintf("nilET == nilError: %v", nilET == nilError)) + check("true", fmt.Sprintf("nilET != nilError: %v", nilET != nilError)) +} + +func check(want, gotfull string) { + got := gotfull[strings.Index(gotfull, ": ")+len(": "):] + if got != want { + panic("want " + want + " got " + got + " from " + gotfull) + } +}