]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: make iface == iface const evaluation respect !=
authorJosh Bleecher Snyder <josharian@gmail.com>
Mon, 10 Apr 2017 19:42:52 +0000 (12:42 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Mon, 10 Apr 2017 20:05:56 +0000 (20:05 +0000)
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>
src/cmd/compile/internal/gc/const.go
test/fixedbugs/issue19911.go [new file with mode: 0644]

index 3826b691572f0f1a9779f1312314139b60de2bdc..9747f13de3f22db552942f9f0d2c9dd1681261f6 100644 (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
diff --git a/test/fixedbugs/issue19911.go b/test/fixedbugs/issue19911.go
new file mode 100644 (file)
index 0000000..af7f598
--- /dev/null
@@ -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)
+       }
+}