]> Cypherpunks repositories - gostls13.git/commitdiff
bug284: test cases for new conversion rules
authorRobert Griesemer <gri@golang.org>
Wed, 2 Jun 2010 16:23:04 +0000 (09:23 -0700)
committerRobert Griesemer <gri@golang.org>
Wed, 2 Jun 2010 16:23:04 +0000 (09:23 -0700)
R=rsc, r, iant
CC=golang-dev
https://golang.org/cl/1465041

test/bugs/bug284.go [new file with mode: 0644]
test/golden.out

diff --git a/test/bugs/bug284.go b/test/bugs/bug284.go
new file mode 100644 (file)
index 0000000..ae40260
--- /dev/null
@@ -0,0 +1,182 @@
+// errchk $G $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
+       q0 = q0
+       q0 = q1
+       q0 = (*struct {
+               x int
+       })(q2) // legal because of special conversion exception for pointers
+       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
+}
index 1bed6599a8d27bb8726e78d03c8984bef1bfd9da..19ae2502300c94f19b4b7cb62a4ac0b67496a944 100644 (file)
@@ -180,3 +180,39 @@ BUG: bug260 failed
 
 =========== bugs/bug274.go
 BUG: errchk: command succeeded unexpectedly
+
+=========== bugs/bug284.go
+BUG: errchk: bugs/bug284.go:33: missing expected error: 'cannot'
+errchk: bugs/bug284.go:36: missing expected error: 'cannot'
+errchk: bugs/bug284.go:37: missing expected error: 'cannot'
+errchk: bugs/bug284.go:38: missing expected error: 'cannot'
+errchk: bugs/bug284.go:56: missing expected error: 'cannot'
+errchk: bugs/bug284.go:59: missing expected error: 'cannot'
+errchk: bugs/bug284.go:60: missing expected error: 'cannot'
+errchk: bugs/bug284.go:61: missing expected error: 'cannot'
+errchk: bugs/bug284.go:71: missing expected error: 'cannot'
+errchk: bugs/bug284.go:74: missing expected error: 'cannot'
+errchk: bugs/bug284.go:75: missing expected error: 'cannot'
+errchk: bugs/bug284.go:76: missing expected error: 'cannot'
+errchk: bugs/bug284.go:95: missing expected error: 'cannot'
+errchk: bugs/bug284.go:97: missing expected error: 'cannot'
+errchk: bugs/bug284.go:107: missing expected error: 'cannot'
+errchk: bugs/bug284.go:110: missing expected error: 'cannot'
+errchk: bugs/bug284.go:111: missing expected error: 'cannot'
+errchk: bugs/bug284.go:112: missing expected error: 'cannot'
+errchk: bugs/bug284.go:130: error message does not match 'cannot'
+errchk: bugs/bug284.go:133: error message does not match 'cannot'
+errchk: bugs/bug284.go:134: error message does not match 'cannot'
+errchk: bugs/bug284.go:135: error message does not match 'cannot'
+errchk: bugs/bug284.go:145: missing expected error: 'cannot'
+errchk: bugs/bug284.go:148: missing expected error: 'cannot'
+errchk: bugs/bug284.go:149: missing expected error: 'cannot'
+errchk: bugs/bug284.go:150: missing expected error: 'cannot'
+errchk: bugs/bug284.go:160: missing expected error: 'cannot'
+errchk: bugs/bug284.go:163: missing expected error: 'cannot'
+errchk: bugs/bug284.go:164: missing expected error: 'cannot'
+errchk: bugs/bug284.go:165: missing expected error: 'cannot'
+errchk: bugs/bug284.go:175: missing expected error: 'cannot'
+errchk: bugs/bug284.go:178: missing expected error: 'cannot'
+errchk: bugs/bug284.go:179: missing expected error: 'cannot'
+errchk: bugs/bug284.go:180: missing expected error: 'cannot'