]> Cypherpunks repositories - gostls13.git/commitdiff
Per discussion earlier today with r and gri: when an interface
authorIan Lance Taylor <iant@golang.org>
Sat, 25 Oct 2008 05:40:32 +0000 (22:40 -0700)
committerIan Lance Taylor <iant@golang.org>
Sat, 25 Oct 2008 05:40:32 +0000 (22:40 -0700)
object has a value of type "int", it should not automatically
convert to type "int32".  That is, the type alias "int" should
be regarded as having been defined as though "type int int32"
appeared outside of the package, and as therefore being a
different type from "int32".

R=ken
DELTA=21  (20 added, 0 deleted, 1 changed)
OCL=17587
CL=17842

test/bugs/bug113.go [new file with mode: 0644]
test/golden.out
test/ken/interbasic.go

diff --git a/test/bugs/bug113.go b/test/bugs/bug113.go
new file mode 100644 (file)
index 0000000..e794868
--- /dev/null
@@ -0,0 +1,20 @@
+// $G $D/$F.go && $L $F.$A && (! ./$A.out || echo BUG: should not succeed)
+
+// Copyright 2009 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
+type I interface { };
+func foo1(i int) int { return i }
+func foo2(i int32) int32 { return i }
+func main() {
+  var i I;
+  i = 1;
+  var v1 int = i;
+  if foo1(v1) != 1 { panicln(1) }
+  var v2 int32 = i.(int).(int32);
+  if foo1(v2) != 1 { panicln(2) }
+  var v3 int32 = i; // This implicit type conversion should fail at runtime.
+  if foo1(v3) != 1 { panicln(3) }
+}
index ec8b29af1d87035a75e7aec18e44fc6c40de83b3..6a138952caa9aa0ca23d4285eac07383a950bf48 100644 (file)
@@ -156,6 +156,9 @@ bugs/bug109.go:6: illegal types for operand: RETURN
        float64
 BUG: should compile
 
+=========== bugs/bug113.go
+BUG: should not succeed
+
 =========== fixedbugs/bug016.go
 fixedbugs/bug016.go:7: overflow converting constant to uint32
 
index 2603d2560e88f0949dc092eb6b33e9105fbff1b0..e4b0b79a4360f863eaf399fda35a8af9ff2a47e4 100644 (file)
@@ -86,7 +86,8 @@ main()
        u64 = 765432;   ia[12] = u64;
 
        s = ia[0];      if s != "xxx" { panicln(0,s); }
-       i32 = ia[1];    if i32 != 12345 { panicln(1,i32); }
+       i32 = ia[1].(int).(int32);
+                       if i32 != 12345 { panicln(1,i32); }
        b = ia[2];      if b != true { panicln(2,b); }
 
        s = ia[3];      if s != "now is" { panicln(3,s); }