From: Ian Lance Taylor Date: Sat, 25 Oct 2008 05:40:32 +0000 (-0700) Subject: Per discussion earlier today with r and gri: when an interface X-Git-Tag: weekly.2009-11-06~2890 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=22a6747999cc25291d2cad0481c95b0cf4d71ab8;p=gostls13.git Per discussion earlier today with r and gri: when an interface 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 --- diff --git a/test/bugs/bug113.go b/test/bugs/bug113.go new file mode 100644 index 0000000000..e794868a4a --- /dev/null +++ b/test/bugs/bug113.go @@ -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) } +} diff --git a/test/golden.out b/test/golden.out index ec8b29af1d..6a138952ca 100644 --- a/test/golden.out +++ b/test/golden.out @@ -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 diff --git a/test/ken/interbasic.go b/test/ken/interbasic.go index 2603d2560e..e4b0b79a43 100644 --- a/test/ken/interbasic.go +++ b/test/ken/interbasic.go @@ -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); }