summaryrefslogtreecommitdiff
path: root/test/bugs
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2010-06-08 18:50:02 -0700
committerRuss Cox <rsc@golang.org>2010-06-08 18:50:02 -0700
commit105c61f5ede0604545bfb2ae58d5627b8ddc0614 (patch)
tree19d1ab733d194831a2bf78d352fc92bb71e86f7a /test/bugs
parent86bca21ef3fb4caf07f58216af511ce6938742e6 (diff)
downloadgo-105c61f5ede0604545bfb2ae58d5627b8ddc0614.tar.gz
gc: new typechecking rules
* Code for assignment, conversions now mirrors spec. * Changed some snprint -> smprint. * Renamed runtime functions to separate interface conversions from type assertions: convT2I, assertI2T, etc. * Correct checking of \U sequences. Fixes issue 840. Fixes issue 830. Fixes issue 778. R=ken2 CC=golang-dev http://codereview.appspot.com/1303042
Diffstat (limited to 'test/bugs')
-rw-r--r--test/bugs/bug284.go191
-rw-r--r--test/bugs/bug285.go116
2 files changed, 0 insertions, 307 deletions
diff --git a/test/bugs/bug284.go b/test/bugs/bug284.go
deleted file mode 100644
index 9e9949bed..000000000
--- a/test/bugs/bug284.go
+++ /dev/null
@@ -1,191 +0,0 @@
-// errchk $G -e $D/$F.go
-
-// Copyright 2010 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.
-
-// Test cases for revised conversion rules.
-
-package main
-
-func main() {
- type NewInt int
- i0 := 0
- var i1 int = 1
- var i2 NewInt = 1
- i0 = i0
- i0 = i1
- i0 = int(i2)
- i1 = i0
- i1 = i1
- i1 = int(i2)
- i2 = NewInt(i0)
- i2 = NewInt(i1)
- i2 = i2
-
- type A1 [3]int
- type A2 [3]NewInt
- var a0 [3]int
- var a1 A1
- var a2 A2
- a0 = a0
- a0 = a1
- a0 = [3]int(a2) // ERROR "cannot"
- a1 = a0
- a1 = a1
- a1 = A1(a2) // ERROR "cannot"
- a2 = A2(a0) // ERROR "cannot"
- a2 = A2(a1) // ERROR "cannot"
- a2 = a2
-
- type S1 struct {
- x int
- }
- type S2 struct {
- x NewInt
- }
- var s0 struct {
- x int
- }
- var s1 S1
- var s2 S2
- s0 = s0
- s0 = s1
- s0 = struct {
- x int
- }(s2) // ERROR "cannot"
- s1 = s0
- s1 = s1
- s1 = S1(s2) // ERROR "cannot"
- s2 = S2(s0) // ERROR "cannot"
- s2 = S2(s1) // ERROR "cannot"
- s2 = s2
-
- type P1 *int
- type P2 *NewInt
- var p0 *int
- var p1 P1
- var p2 P2
- p0 = p0
- p0 = p1
- p0 = (*int)(p2) // ERROR "cannot"
- p1 = p0
- p1 = p1
- p1 = P1(p2) // ERROR "cannot"
- p2 = P2(p0) // ERROR "cannot"
- p2 = P2(p1) // ERROR "cannot"
- p2 = p2
-
- type Q1 *struct {
- x int
- }
- type Q2 *S1
- var q0 *struct {
- x int
- }
- var q1 Q1
- var q2 Q2
- var ps1 *S1
- q0 = q0
- q0 = q1
- q0 = (*struct {
- x int
- })(ps1) // legal because of special conversion exception for pointers
- q0 = (*struct {
- x int
- })(q2) // ERROR "cannot"
- q1 = q0
- q1 = q1
- q1 = Q1(q2) // ERROR "cannot"
- q2 = (*S1)(q0) // legal because of special conversion exception for pointers
- q2 = Q2(q1) // ERROR "cannot"
- q2 = q2
-
- type F1 func(x NewInt) int
- type F2 func(x int) NewInt
- var f0 func(x NewInt) int
- var f1 F1
- var f2 F2
- f0 = f0
- f0 = f1
- f0 = func(x NewInt) int(f2) // ERROR "cannot"
- f1 = f0
- f1 = f1
- f1 = F1(f2) // ERROR "cannot"
- f2 = F2(f0) // ERROR "cannot"
- f2 = F2(f1) // ERROR "cannot"
- f2 = f2
-
- type X1 interface {
- f() int
- }
- type X2 interface {
- f() NewInt
- }
- var x0 interface {
- f() int
- }
- var x1 X1
- var x2 X2
- x0 = x0
- x0 = x1
- x0 = interface {
- f() int
- }(x2) // ERROR "cannot|need type assertion"
- x1 = x0
- x1 = x1
- x1 = X1(x2) // ERROR "cannot|need type assertion"
- x2 = X2(x0) // ERROR "cannot|need type assertion"
- x2 = X2(x1) // ERROR "cannot|need type assertion"
- x2 = x2
-
- type L1 []int
- type L2 []NewInt
- var l0 []int
- var l1 L1
- var l2 L2
- l0 = l0
- l0 = l1
- l0 = []int(l2) // ERROR "cannot"
- l1 = l0
- l1 = l1
- l1 = L1(l2) // ERROR "cannot"
- l2 = L2(l0) // ERROR "cannot"
- l2 = L2(l1) // ERROR "cannot"
- l2 = l2
-
- type M1 map[string]int
- type M2 map[string]NewInt
- var m0 []int
- var m1 L1
- var m2 L2
- m0 = m0
- m0 = m1
- m0 = []int(m2) // ERROR "cannot"
- m1 = m0
- m1 = m1
- m1 = L1(m2) // ERROR "cannot"
- m2 = L2(m0) // ERROR "cannot"
- m2 = L2(m1) // ERROR "cannot"
- m2 = m2
-
- type C1 chan int
- type C2 chan NewInt
- var c0 chan int
- var c1 C1
- var c2 C2
- c0 = c0
- c0 = c1
- c0 = chan int(c2) // ERROR "cannot"
- c1 = c0
- c1 = c1
- c1 = C1(c2) // ERROR "cannot"
- c2 = C2(c0) // ERROR "cannot"
- c2 = C2(c1) // ERROR "cannot"
- c2 = c2
-
- // internal compiler error (6g and gccgo)
- type T interface{}
- var _ T = 17 // assignment compatible
- _ = T(17) // internal compiler error even though assignment compatible
-}
diff --git a/test/bugs/bug285.go b/test/bugs/bug285.go
deleted file mode 100644
index 59499c983..000000000
--- a/test/bugs/bug285.go
+++ /dev/null
@@ -1,116 +0,0 @@
-// $G $D/$F.go && $L $F.go && ./$A.out || echo BUG: bug285
-
-// Copyright 2010 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.
-
-// Test for issue 778: Map key values that are assignment
-// compatible with the map key type must be accepted according
-// to the spec: http://golang.org/doc/go_spec.html#Indexes .
-
-package main
-
-type T2 struct {
- x int
-}
-
-func (t *T2) f() int { return t.x }
-
-func main() {
- type B bool
- b := B(false)
- mb := make(map[B]int)
- mb[false] = 42 // this should work: false is assignment compatible with B
- mb[b] = 42
-
- type Z int
- z := Z(0)
- mz := make(map[Z]int)
- mz[0] = 42
- mz[z] = 42
-
- type S string
- s := S("foo")
- ms := make(map[S]int)
- ms["foo"] = 42
- ms[s] = 42
-
- type T struct {
- x int
- }
- type P *T
- p := P(nil)
- mp := make(map[P]int)
- mp[nil] = 42
- mp[p] = 42
- mp[&T{7}] = 42
-
- type F func(x int)
- f := func(x int) {}
- mf := make(map[F]int)
- mf[nil] = 42
- mf[f] = 42
- mf[func(x int) {}] = 42
-
- type M map[int]int
- m := make(M)
- mm := make(map[M]int)
- mm[nil] = 42
- mm[m] = 42
- mm[make(M)] = 42
-
- type C chan int
- c := make(C)
- mc := make(map[C]int)
- mc[nil] = 42
- mc[c] = 42
- mc[make(C)] = 42
-
- type I1 interface{}
- type I2 interface {
- f() int
- }
- var i0 interface{} = z
- var i1 I1 = p
- m0 := make(map[interface{}]int)
- m1 := make(map[I1]int)
- m2 := make(map[I2]int)
- m0[i0] = 42
- m0[i1] = 42
- m0[z] = 42 // this should work: z is assignment-compatible with interface{}
- m0[new(struct {
- x int
- })] = 42 // this should work: *struct{x int} is assignment-compatible with interface{}
- m0[p] = 42 // this should work: p is assignment-compatible with interface{}
- m0[false] = 42 // this should work: false is assignment-compatible with interface{}
- m0[17] = 42 // this should work: 17 is assignment-compatible with interface{}
- m0["foo"] = 42 // this should work: "foo" is assignment-compatible with interface{}
-
- m1[i0] = 42
- m1[i1] = 42
- m1[new(struct {
- x int
- })] = 42 // this should work: *struct{x int} is assignment-compatible with I1
- m1[false] = 42 // this should work: false is assignment-compatible with I1
- m1[17] = 42 // this should work: 17 is assignment-compatible with I1
- m1["foo"] = 42 // this should work: "foo" is assignment-compatible with I1
-
- m2[new(T2)] = 42 // this should work: *T2 is assignment-compatible with I2
-}
-
-/*
-6g -e bug286.go
-bug286.go:23: invalid map index false - need type B
-bug286.go:80: invalid map index z - need type interface { }
-bug286.go:83: invalid map index new(struct { x int }) - need type interface { }
-bug286.go:84: invalid map index p - need type interface { }
-bug286.go:85: invalid map index false - need type interface { }
-bug286.go:86: invalid map index 17 - need type interface { }
-bug286.go:87: invalid map index "foo" - need type interface { }
-bug286.go:93: invalid map index new(struct { x int }) - need type I1
-bug286.go:94: invalid map index false - need type I1
-bug286.go:95: invalid map index 17 - need type I1
-bug286.go:96: invalid map index "foo" - need type I1
-bug286.go:99: invalid map index new(T2) - need type I2
-bug286.go:100: invalid map index t2 - need type I2
-*/