1
0
mirror of https://github.com/golang/go synced 2024-11-22 05:04:40 -07:00

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
This commit is contained in:
Ian Lance Taylor 2008-10-24 22:40:32 -07:00
parent a785e8ac6d
commit 22a6747999
3 changed files with 25 additions and 1 deletions

20
test/bugs/bug113.go Normal file
View File

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

View 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

View 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); }