]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fix export type conversion loss in inlined func body
authorRuss Cox <rsc@golang.org>
Mon, 14 Dec 2015 19:07:21 +0000 (14:07 -0500)
committerRuss Cox <rsc@golang.org>
Wed, 16 Dec 2015 20:30:04 +0000 (20:30 +0000)
Fixes #12677.

Change-Id: I72012f55615fcf5f4a16c054706c9bcd82e49ccd
Reviewed-on: https://go-review.googlesource.com/17817
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/compile/internal/gc/fmt.go
test/fixedbugs/issue12677.dir/p.go [new file with mode: 0644]
test/fixedbugs/issue12677.dir/q.go [new file with mode: 0644]
test/fixedbugs/issue12677.go [new file with mode: 0644]

index 5f108724e08755261fd26a655678ef0d26f5bb54..1cbaf17f38c60a877449430d0ef817690f90e168 100644 (file)
@@ -1120,7 +1120,7 @@ func exprfmt(n *Node, prec int) string {
                if n.Val().Ctype() == CTNIL && n.Orig != nil && n.Orig != n {
                        return exprfmt(n.Orig, prec)
                }
-               if n.Type != nil && n.Type != Types[n.Type.Etype] && n.Type != idealbool && n.Type != idealstring {
+               if n.Type != nil && n.Type.Etype != TIDEAL && n.Type.Etype != TNIL && n.Type != idealbool && n.Type != idealstring {
                        // Need parens when type begins with what might
                        // be misinterpreted as a unary operator: * or <-.
                        if Isptr[n.Type.Etype] || (n.Type.Etype == TCHAN && n.Type.Chan == Crecv) {
diff --git a/test/fixedbugs/issue12677.dir/p.go b/test/fixedbugs/issue12677.dir/p.go
new file mode 100644 (file)
index 0000000..e395071
--- /dev/null
@@ -0,0 +1,8 @@
+// Copyright 2015 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 p
+func Baz(f int) float64 {
+    return 1 / float64(int(1)<<(uint(f)))
+}
diff --git a/test/fixedbugs/issue12677.dir/q.go b/test/fixedbugs/issue12677.dir/q.go
new file mode 100644 (file)
index 0000000..fd39c8a
--- /dev/null
@@ -0,0 +1,7 @@
+// Copyright 2015 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 q
+import "./p"
+func f() { println(p.Baz(2)) }
diff --git a/test/fixedbugs/issue12677.go b/test/fixedbugs/issue12677.go
new file mode 100644 (file)
index 0000000..6ad7161
--- /dev/null
@@ -0,0 +1,9 @@
+// compiledir
+
+// Copyright 2015 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 12677: Type loss during export/import of inlined function body.
+
+package ignored