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 <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Josh Bleecher Snyder 2017-04-10 12:42:52 -07:00
parent 44bd39c3a4
commit b83a916f71
2 changed files with 37 additions and 0 deletions

View file

@ -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

View file

@ -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)
}
}