Commit 22a67479 authored by Ian Lance Taylor's avatar Ian Lance Taylor

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
parent a785e8ac
// $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) }
}
...@@ -156,6 +156,9 @@ bugs/bug109.go:6: illegal types for operand: RETURN ...@@ -156,6 +156,9 @@ bugs/bug109.go:6: illegal types for operand: RETURN
float64 float64
BUG: should compile BUG: should compile
=========== bugs/bug113.go
BUG: should not succeed
=========== fixedbugs/bug016.go =========== fixedbugs/bug016.go
fixedbugs/bug016.go:7: overflow converting constant to uint32 fixedbugs/bug016.go:7: overflow converting constant to uint32
......
...@@ -86,7 +86,8 @@ main() ...@@ -86,7 +86,8 @@ main()
u64 = 765432; ia[12] = u64; u64 = 765432; ia[12] = u64;
s = ia[0]; if s != "xxx" { panicln(0,s); } 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); } b = ia[2]; if b != true { panicln(2,b); }
s = ia[3]; if s != "now is" { panicln(3,s); } s = ia[3]; if s != "now is" { panicln(3,s); }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment