diff options
author | Russ Cox <rsc@golang.org> | 2010-06-08 18:50:02 -0700 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2010-06-08 18:50:02 -0700 |
commit | 0b814afd0a2fa1dded3eaf4d2f79b20438842955 (patch) | |
tree | 19d1ab733d194831a2bf78d352fc92bb71e86f7a /test | |
parent | 11704e355aa8f39669a36fe56c01d17deab60658 (diff) | |
download | golang-0b814afd0a2fa1dded3eaf4d2f79b20438842955.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')
-rw-r--r-- | test/assign1.go | 343 | ||||
-rw-r--r-- | test/convert3.go | 5 | ||||
-rw-r--r-- | test/fixedbugs/bug248.dir/bug3.go | 24 | ||||
-rw-r--r-- | test/fixedbugs/bug251.go | 4 | ||||
-rw-r--r-- | test/fixedbugs/bug284.go (renamed from test/bugs/bug284.go) | 0 | ||||
-rw-r--r-- | test/fixedbugs/bug285.go (renamed from test/bugs/bug285.go) | 2 | ||||
-rw-r--r-- | test/golden.out | 55 | ||||
-rw-r--r-- | test/interface/explicit.go | 41 | ||||
-rw-r--r-- | test/interface/pointer.go | 16 | ||||
-rw-r--r-- | test/interface/receiver1.go | 71 | ||||
-rw-r--r-- | test/named.go | 474 | ||||
-rw-r--r-- | test/named1.go | 69 |
12 files changed, 712 insertions, 392 deletions
diff --git a/test/assign1.go b/test/assign1.go new file mode 100644 index 000000000..452f90f1c --- /dev/null +++ b/test/assign1.go @@ -0,0 +1,343 @@ +// errchk $G -e $D/$F.go + +// 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 ( + A [10]int + B []int + C chan int + F func() int + I interface { + m() int + } + M map[int]int + P *int + S struct { + X int + } + + A1 [10]int + B1 []int + C1 chan int + F1 func() int + I1 interface { + m() int + } + M1 map[int]int + P1 *int + S1 struct { + X int + } +) + +var ( + a0 [10]int + b0 []int + c0 chan int + f0 func() int + i0 interface { + m() int + } + m0 map[int]int + p0 *int + s0 struct { + X int + } + + a A + b B + c C + f F + i I + m M + p P + s S + + a1 A1 + b1 B1 + c1 C1 + f1 F1 + i1 I1 + m1 M1 + p1 P1 + s1 S1 + + pa0 *[10]int + pb0 *[]int + pc0 *chan int + pf0 *func() int + pi0 *interface { + m() int + } + pm0 *map[int]int + pp0 **int + ps0 *struct { + X int + } + + pa *A + pb *B + pc *C + pf *F + pi *I + pm *M + pp *P + ps *S + + pa1 *A1 + pb1 *B1 + pc1 *C1 + pf1 *F1 + pi1 *I1 + pm1 *M1 + pp1 *P1 + ps1 *S1 +) + +func main() { + a0 = a + a0 = a1 + a = a0 + a = a1 // ERROR "cannot use" + a1 = a0 + a1 = a // ERROR "cannot use" + + b0 = b + b0 = b1 + b = b0 + b = b1 // ERROR "cannot use" + b1 = b0 + b1 = b // ERROR "cannot use" + + c0 = c + c0 = c1 + c = c0 + c = c1 // ERROR "cannot use" + c1 = c0 + c1 = c // ERROR "cannot use" + + f0 = f + f0 = f1 + f = f0 + f = f1 // ERROR "cannot use" + f1 = f0 + f1 = f // ERROR "cannot use" + + i0 = i + i0 = i1 + i = i0 + i = i1 + i1 = i0 + i1 = i + + m0 = m + m0 = m1 + m = m0 + m = m1 // ERROR "cannot use" + m1 = m0 + m1 = m // ERROR "cannot use" + + p0 = p + p0 = p1 + p = p0 + p = p1 // ERROR "cannot use" + p1 = p0 + p1 = p // ERROR "cannot use" + + s0 = s + s0 = s1 + s = s0 + s = s1 // ERROR "cannot use" + s1 = s0 + s1 = s // ERROR "cannot use" + + pa0 = pa // ERROR "cannot use" + pa0 = pa1 // ERROR "cannot use" + pa = pa0 // ERROR "cannot use" + pa = pa1 // ERROR "cannot use" + pa1 = pa0 // ERROR "cannot use" + pa1 = pa // ERROR "cannot use" + + pb0 = pb // ERROR "cannot use" + pb0 = pb1 // ERROR "cannot use" + pb = pb0 // ERROR "cannot use" + pb = pb1 // ERROR "cannot use" + pb1 = pb0 // ERROR "cannot use" + pb1 = pb // ERROR "cannot use" + + pc0 = pc // ERROR "cannot use" + pc0 = pc1 // ERROR "cannot use" + pc = pc0 // ERROR "cannot use" + pc = pc1 // ERROR "cannot use" + pc1 = pc0 // ERROR "cannot use" + pc1 = pc // ERROR "cannot use" + + pf0 = pf // ERROR "cannot use" + pf0 = pf1 // ERROR "cannot use" + pf = pf0 // ERROR "cannot use" + pf = pf1 // ERROR "cannot use" + pf1 = pf0 // ERROR "cannot use" + pf1 = pf // ERROR "cannot use" + + pi0 = pi // ERROR "cannot use" + pi0 = pi1 // ERROR "cannot use" + pi = pi0 // ERROR "cannot use" + pi = pi1 // ERROR "cannot use" + pi1 = pi0 // ERROR "cannot use" + pi1 = pi // ERROR "cannot use" + + pm0 = pm // ERROR "cannot use" + pm0 = pm1 // ERROR "cannot use" + pm = pm0 // ERROR "cannot use" + pm = pm1 // ERROR "cannot use" + pm1 = pm0 // ERROR "cannot use" + pm1 = pm // ERROR "cannot use" + + pp0 = pp // ERROR "cannot use" + pp0 = pp1 // ERROR "cannot use" + pp = pp0 // ERROR "cannot use" + pp = pp1 // ERROR "cannot use" + pp1 = pp0 // ERROR "cannot use" + pp1 = pp // ERROR "cannot use" + + ps0 = ps // ERROR "cannot use" + ps0 = ps1 // ERROR "cannot use" + ps = ps0 // ERROR "cannot use" + ps = ps1 // ERROR "cannot use" + ps1 = ps0 // ERROR "cannot use" + ps1 = ps // ERROR "cannot use" + + + a0 = [10]int(a) + a0 = [10]int(a1) + a = A(a0) + a = A(a1) + a1 = A1(a0) + a1 = A1(a) + + b0 = []int(b) + b0 = []int(b1) + b = B(b0) + b = B(b1) + b1 = B1(b0) + b1 = B1(b) + + c0 = chan int(c) + c0 = chan int(c1) + c = C(c0) + c = C(c1) + c1 = C1(c0) + c1 = C1(c) + + f0 = func() int(f) + f0 = func() int(f1) + f = F(f0) + f = F(f1) + f1 = F1(f0) + f1 = F1(f) + + i0 = interface { + m() int + }(i) + i0 = interface { + m() int + }(i1) + i = I(i0) + i = I(i1) + i1 = I1(i0) + i1 = I1(i) + + m0 = map[int]int(m) + m0 = map[int]int(m1) + m = M(m0) + m = M(m1) + m1 = M1(m0) + m1 = M1(m) + + p0 = (*int)(p) + p0 = (*int)(p1) + p = P(p0) + p = P(p1) + p1 = P1(p0) + p1 = P1(p) + + s0 = struct { + X int + }(s) + s0 = struct { + X int + }(s1) + s = S(s0) + s = S(s1) + s1 = S1(s0) + s1 = S1(s) + + pa0 = (*[10]int)(pa) + pa0 = (*[10]int)(pa1) + pa = (*A)(pa0) + pa = (*A)(pa1) + pa1 = (*A1)(pa0) + pa1 = (*A1)(pa) + + pb0 = (*[]int)(pb) + pb0 = (*[]int)(pb1) + pb = (*B)(pb0) + pb = (*B)(pb1) + pb1 = (*B1)(pb0) + pb1 = (*B1)(pb) + + pc0 = (*chan int)(pc) + pc0 = (*chan int)(pc1) + pc = (*C)(pc0) + pc = (*C)(pc1) + pc1 = (*C1)(pc0) + pc1 = (*C1)(pc) + + pf0 = (*func() int)(pf) + pf0 = (*func() int)(pf1) + pf = (*F)(pf0) + pf = (*F)(pf1) + pf1 = (*F1)(pf0) + pf1 = (*F1)(pf) + + pi0 = (*interface { + m() int + })(pi) + pi0 = (*interface { + m() int + })(pi1) + pi = (*I)(pi0) + pi = (*I)(pi1) + pi1 = (*I1)(pi0) + pi1 = (*I1)(pi) + + pm0 = (*map[int]int)(pm) + pm0 = (*map[int]int)(pm1) + pm = (*M)(pm0) + pm = (*M)(pm1) + pm1 = (*M1)(pm0) + pm1 = (*M1)(pm) + + pp0 = (**int)(pp) + pp0 = (**int)(pp1) + pp = (*P)(pp0) + pp = (*P)(pp1) + pp1 = (*P1)(pp0) + pp1 = (*P1)(pp) + + ps0 = (*struct { + X int + })(ps) + ps0 = (*struct { + X int + })(ps1) + ps = (*S)(ps0) + ps = (*S)(ps1) + ps1 = (*S1)(ps0) + ps1 = (*S1)(ps) + +} diff --git a/test/convert3.go b/test/convert3.go index cb0500012..5f1f0dd94 100644 --- a/test/convert3.go +++ b/test/convert3.go @@ -18,8 +18,9 @@ var f2 = []int(e) var g = []int(nil) -type H *[4]int +type H []int type J []int + var h H -var j1 J = h // ERROR "compat|illegal|cannot|cannot" +var j1 J = h // ERROR "compat|illegal|cannot" var j2 = J(h) diff --git a/test/fixedbugs/bug248.dir/bug3.go b/test/fixedbugs/bug248.dir/bug3.go index 41f559b52..c96bf1676 100644 --- a/test/fixedbugs/bug248.dir/bug3.go +++ b/test/fixedbugs/bug248.dir/bug3.go @@ -34,14 +34,14 @@ func (t1) M(p1.T) {} var i0 I0 = t0(0) // ok var i1 I1 = t1(0) // ok -var i2 I0 = t1(0) // ERROR "is not|incompatible" -var i3 I1 = t0(0) // ERROR "is not|incompatible" +var i2 I0 = t1(0) // ERROR "does not implement|incompatible" +var i3 I1 = t0(0) // ERROR "does not implement|incompatible" var p0i p0.I = t0(0) // ok var p1i p1.I = t1(0) // ok -var p0i1 p0.I = t1(0) // ERROR "is not|incompatible" -var p0i2 p1.I = t0(0) // ERROR "is not|incompatible" +var p0i1 p0.I = t1(0) // ERROR "does not implement|incompatible" +var p0i2 p1.I = t0(0) // ERROR "does not implement|incompatible" func main() { // check that cannot assign one to the other, @@ -52,14 +52,14 @@ func main() { v0 = p0.T(v1) v1 = p1.T(v0) - i0 = i1 // ERROR "need type assertion|incompatible" - i1 = i0 // ERROR "need type assertion|incompatible" - p0i = i1 // ERROR "need type assertion|incompatible" - p1i = i0 // ERROR "need type assertion|incompatible" - i0 = p1i // ERROR "need type assertion|incompatible" - i1 = p0i // ERROR "need type assertion|incompatible" - p0i = p1i // ERROR "need type assertion|incompatible" - p1i = p0i // ERROR "need type assertion|incompatible" + i0 = i1 // ERROR "cannot use|incompatible" + i1 = i0 // ERROR "cannot use|incompatible" + p0i = i1 // ERROR "cannot use|incompatible" + p1i = i0 // ERROR "cannot use|incompatible" + i0 = p1i // ERROR "cannot use|incompatible" + i1 = p0i // ERROR "cannot use|incompatible" + p0i = p1i // ERROR "cannot use|incompatible" + p1i = p0i // ERROR "cannot use|incompatible" i0 = p0i p0i = i0 diff --git a/test/fixedbugs/bug251.go b/test/fixedbugs/bug251.go index 6ddc4a5a6..37dec9055 100644 --- a/test/fixedbugs/bug251.go +++ b/test/fixedbugs/bug251.go @@ -12,10 +12,10 @@ type I1 interface { } type I2 interface { - I1 // ERROR "loop|interface" + I1 // ERROR "loop|interface" } -var i1 I1 = i2 // ERROR "need type assertion" +var i1 I1 = i2 // ERROR "missing m method|need type assertion" var i2 I2 var i2a I2 = i1 diff --git a/test/bugs/bug284.go b/test/fixedbugs/bug284.go index 9e9949bed..9e9949bed 100644 --- a/test/bugs/bug284.go +++ b/test/fixedbugs/bug284.go diff --git a/test/bugs/bug285.go b/test/fixedbugs/bug285.go index 59499c983..544d3487e 100644 --- a/test/bugs/bug285.go +++ b/test/fixedbugs/bug285.go @@ -1,4 +1,4 @@ -// $G $D/$F.go && $L $F.go && ./$A.out || echo BUG: bug285 +// $G $D/$F.go && $L $F.$A && ./$A.out || echo BUG: bug285 // Copyright 2010 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style diff --git a/test/golden.out b/test/golden.out index cda1ec412..1bed6599a 100644 --- a/test/golden.out +++ b/test/golden.out @@ -180,58 +180,3 @@ 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:96: missing expected error: 'cannot' -errchk: bugs/bug284.go:99: missing expected error: 'cannot' -errchk: bugs/bug284.go:101: missing expected error: 'cannot' -errchk: bugs/bug284.go:111: missing expected error: 'cannot' -errchk: bugs/bug284.go:114: missing expected error: 'cannot' -errchk: bugs/bug284.go:115: missing expected error: 'cannot' -errchk: bugs/bug284.go:116: missing expected error: 'cannot' -errchk: bugs/bug284.go:134: missing expected error: 'cannot|need type assertion' -errchk: bugs/bug284.go:137: missing expected error: 'cannot|need type assertion' -errchk: bugs/bug284.go:138: missing expected error: 'cannot|need type assertion' -errchk: bugs/bug284.go:139: missing expected error: 'cannot|need type assertion' -errchk: bugs/bug284.go:149: missing expected error: 'cannot' -errchk: bugs/bug284.go:152: missing expected error: 'cannot' -errchk: bugs/bug284.go:153: missing expected error: 'cannot' -errchk: bugs/bug284.go:154: missing expected error: 'cannot' -errchk: bugs/bug284.go:164: missing expected error: 'cannot' -errchk: bugs/bug284.go:167: missing expected error: 'cannot' -errchk: bugs/bug284.go:168: missing expected error: 'cannot' -errchk: bugs/bug284.go:169: missing expected error: 'cannot' -errchk: bugs/bug284.go:179: missing expected error: 'cannot' -errchk: bugs/bug284.go:182: missing expected error: 'cannot' -errchk: bugs/bug284.go:183: missing expected error: 'cannot' -errchk: bugs/bug284.go:184: missing expected error: 'cannot' -errchk: bugs/bug284.go: unmatched error messages: -================================================== -bugs/bug284.go:190: internal compiler error: typename ideal -================================================== - -=========== bugs/bug285.go -bugs/bug285.go:23: invalid map index false - need type B -bugs/bug285.go:80: invalid map index z - need type interface { } -bugs/bug285.go:83: invalid map index new(struct { x int }) - need type interface { } -bugs/bug285.go:84: invalid map index p - need type interface { } -bugs/bug285.go:85: invalid map index false - need type interface { } -bugs/bug285.go:86: invalid map index 17 - need type interface { } -bugs/bug285.go:87: invalid map index "foo" - need type interface { } -bugs/bug285.go:93: invalid map index new(struct { x int }) - need type I1 -bugs/bug285.go:94: invalid map index false - need type I1 -bugs/bug285.go:95: invalid map index 17 - need type I1 -bugs/bug285.go:95: too many errors -BUG: bug285 diff --git a/test/interface/explicit.go b/test/interface/explicit.go index bd1bd19a9..797cec80e 100644 --- a/test/interface/explicit.go +++ b/test/interface/explicit.go @@ -8,34 +8,45 @@ package main -type T struct { a int } +type T struct { + a int +} + var t *T -type I interface { M() } +type I interface { + M() +} + var i I -type I2 interface { M(); N(); } +type I2 interface { + M() + N() +} + var i2 I2 -type E interface { } +type E interface{} + var e E func main() { - e = t; // ok - t = e; // ERROR "need explicit|need type assertion" + e = t // ok + t = e // ERROR "need explicit|need type assertion" // neither of these can work, // because i has an extra method // that t does not, so i cannot contain a t. - i = t; // ERROR "missing|incompatible|is not" - t = i; // ERROR "missing|incompatible|is not" + i = t // ERROR "incompatible|missing M method" + t = i // ERROR "incompatible|need type assertion" + + i = i2 // ok + i2 = i // ERROR "missing N method" - i = i2; // ok - i2 = i; // ERROR "need explicit|need type assertion" - - i = I(i2); // ok - i2 = I2(i); // ERROR "need explicit|need type assertion" + i = I(i2) // ok + i2 = I2(i) // ERROR "missing N method" - e = E(t); // ok - t = T(e); // ERROR "need explicit|need type assertion|incompatible" + e = E(t) // ok + t = T(e) // ERROR "need explicit|need type assertion|incompatible" } diff --git a/test/interface/pointer.go b/test/interface/pointer.go index be24952ff..e628b558e 100644 --- a/test/interface/pointer.go +++ b/test/interface/pointer.go @@ -9,28 +9,28 @@ package main type Inst interface { - Next() *Inst; + Next() *Inst } type Regexp struct { - code []Inst; - start Inst; + code []Inst + start Inst } type Start struct { - foo *Inst; + foo *Inst } func (start *Start) Next() *Inst { return nil } func AddInst(Inst) *Inst { - print("ok in addinst\n"); + print("ok in addinst\n") return nil } func main() { - print("call addinst\n"); - var x Inst = AddInst(new(Start)); // ERROR "illegal|incompatible|is not" - print("return from addinst\n"); + print("call addinst\n") + var x Inst = AddInst(new(Start)) // ERROR "pointer to interface" + print("return from addinst\n") } diff --git a/test/interface/receiver1.go b/test/interface/receiver1.go index 8ce96424e..51312d000 100644 --- a/test/interface/receiver1.go +++ b/test/interface/receiver1.go @@ -9,41 +9,50 @@ package main type T int + func (t T) V() func (t *T) P() -type V interface { V() } -type P interface { P(); V() } +type V interface { + V() +} +type P interface { + P() + V() +} -type S struct { T; } -type SP struct { *T; } +type S struct { + T +} +type SP struct { + *T +} func main() { - var t T; - var v V; - var p P; - var s S; - var sp SP; - - v = t; - p = t; // ERROR "is not|requires a pointer" - _, _= v, p; - v = &t; - p = &t; - _, _= v, p; - - v = s; - p = s; // ERROR "is not|requires a pointer" - _, _= v, p; - v = &s; - p = &s; - _, _= v, p; - - v = sp; - p = sp; // no error! - _, _= v, p; - v = &sp; - p = &sp; - _, _= v, p; + var t T + var v V + var p P + var s S + var sp SP + + v = t + p = t // ERROR "does not implement|requires a pointer" + _, _ = v, p + v = &t + p = &t + _, _ = v, p + + v = s + p = s // ERROR "does not implement|requires a pointer" + _, _ = v, p + v = &s + p = &s + _, _ = v, p + + v = sp + p = sp // no error! + _, _ = v, p + v = &sp + p = &sp + _, _ = v, p } - diff --git a/test/named.go b/test/named.go index a52490215..d2039bab4 100644 --- a/test/named.go +++ b/test/named.go @@ -20,13 +20,13 @@ type String string // Calling these functions checks at compile time that the argument // can be converted implicitly to (used as) the given type. -func asArray(Array) {} -func asBool(Bool) {} -func asChan(Chan) {} -func asFloat(Float) {} -func asInt(Int) {} -func asMap(Map) {} -func asSlice(Slice) {} +func asArray(Array) {} +func asBool(Bool) {} +func asChan(Chan) {} +func asFloat(Float) {} +func asInt(Int) {} +func asMap(Map) {} +func asSlice(Slice) {} func asString(String) {} func (Map) M() {} @@ -35,247 +35,247 @@ func (Map) M() {} // These functions check at run time that the default type // (in the absence of any implicit conversion hints) // is the given type. -func isArray(x interface{}) { _ = x.(Array) } -func isBool(x interface{}) { _ = x.(Bool) } -func isChan(x interface{}) { _ = x.(Chan) } -func isFloat(x interface{}) { _ = x.(Float) } -func isInt(x interface{}) { _ = x.(Int) } -func isMap(x interface{}) { _ = x.(Map) } -func isSlice(x interface{}) { _ = x.(Slice) } +func isArray(x interface{}) { _ = x.(Array) } +func isBool(x interface{}) { _ = x.(Bool) } +func isChan(x interface{}) { _ = x.(Chan) } +func isFloat(x interface{}) { _ = x.(Float) } +func isInt(x interface{}) { _ = x.(Int) } +func isMap(x interface{}) { _ = x.(Map) } +func isSlice(x interface{}) { _ = x.(Slice) } func isString(x interface{}) { _ = x.(String) } func main() { var ( - a Array; - b Bool = true; - c Chan = make(Chan); - f Float = 1; - i Int = 1; - m Map = make(Map); - slice Slice = make(Slice, 10); - str String = "hello"; + a Array + b Bool = true + c Chan = make(Chan) + f Float = 1 + i Int = 1 + m Map = make(Map) + slice Slice = make(Slice, 10) + str String = "hello" ) - asArray(a); - isArray(a); - asArray(*&a); - isArray(*&a); - asArray(Array{}); - isArray(Array{}); + asArray(a) + isArray(a) + asArray(*&a) + isArray(*&a) + asArray(Array{}) + isArray(Array{}) - asBool(b); - isBool(b); - asBool(!b); - isBool(!b); - asBool(true); - asBool(*&b); - isBool(*&b); - asBool(Bool(true)); - isBool(Bool(true)); + asBool(b) + isBool(b) + asBool(!b) + isBool(!b) + asBool(true) + asBool(*&b) + isBool(*&b) + asBool(Bool(true)) + isBool(Bool(true)) - asChan(c); - isChan(c); - asChan(make(Chan)); - isChan(make(Chan)); - asChan(*&c); - isChan(*&c); - asChan(Chan(nil)); - isChan(Chan(nil)); + asChan(c) + isChan(c) + asChan(make(Chan)) + isChan(make(Chan)) + asChan(*&c) + isChan(*&c) + asChan(Chan(nil)) + isChan(Chan(nil)) - asFloat(f); - isFloat(f); - asFloat(-f); - isFloat(-f); - asFloat(+f); - isFloat(+f); - asFloat(f+1); - isFloat(f+1); - asFloat(1+f); - isFloat(1+f); - asFloat(f+f); - isFloat(f+f); - f++; - f+=2; - asFloat(f-1); - isFloat(f-1); - asFloat(1-f); - isFloat(1-f); - asFloat(f-f); - isFloat(f-f); - f--; - f-=2; - asFloat(f*2.5); - isFloat(f*2.5); - asFloat(2.5*f); - isFloat(2.5*f); - asFloat(f*f); - isFloat(f*f); - f*=4; - asFloat(f/2.5); - isFloat(f/2.5); - asFloat(2.5/f); - isFloat(2.5/f); - asFloat(f/f); - isFloat(f/f); - f/=4; - asFloat(f); - isFloat(f); - f = 5; - asFloat(*&f); - isFloat(*&f); - asFloat(234); - asFloat(Float(234)); - isFloat(Float(234)); - asFloat(1.2); - asFloat(Float(i)); - isFloat(Float(i)); + asFloat(f) + isFloat(f) + asFloat(-f) + isFloat(-f) + asFloat(+f) + isFloat(+f) + asFloat(f + 1) + isFloat(f + 1) + asFloat(1 + f) + isFloat(1 + f) + asFloat(f + f) + isFloat(f + f) + f++ + f += 2 + asFloat(f - 1) + isFloat(f - 1) + asFloat(1 - f) + isFloat(1 - f) + asFloat(f - f) + isFloat(f - f) + f-- + f -= 2 + asFloat(f * 2.5) + isFloat(f * 2.5) + asFloat(2.5 * f) + isFloat(2.5 * f) + asFloat(f * f) + isFloat(f * f) + f *= 4 + asFloat(f / 2.5) + isFloat(f / 2.5) + asFloat(2.5 / f) + isFloat(2.5 / f) + asFloat(f / f) + isFloat(f / f) + f /= 4 + asFloat(f) + isFloat(f) + f = 5 + asFloat(*&f) + isFloat(*&f) + asFloat(234) + asFloat(Float(234)) + isFloat(Float(234)) + asFloat(1.2) + asFloat(Float(i)) + isFloat(Float(i)) - asInt(i); - isInt(i); - asInt(-i); - isInt(-i); - asInt(^i); - isInt(^i); - asInt(+i); - isInt(+i); - asInt(i+1); - isInt(i+1); - asInt(1+i); - isInt(1+i); - asInt(i+i); - isInt(i+i); - i++; - i+=1; - asInt(i-1); - isInt(i-1); - asInt(1-i); - isInt(1-i); - asInt(i-i); - isInt(i-i); - i--; - i-=1; - asInt(i*2); - isInt(i*2); - asInt(2*i); - isInt(2*i); - asInt(i*i); - isInt(i*i); - i*=2; - asInt(i/5); - isInt(i/5); - asInt(5/i); - isInt(5/i); - asInt(i/i); - isInt(i/i); - i/=2; - asInt(i%5); - isInt(i%5); - asInt(5%i); - isInt(5%i); - asInt(i%i); - isInt(i%i); - i%=2; - asInt(i&5); - isInt(i&5); - asInt(5&i); - isInt(5&i); - asInt(i&i); - isInt(i&i); - i&=2; - asInt(i&^5); - isInt(i&^5); - asInt(5&^i); - isInt(5&^i); - asInt(i&^i); - isInt(i&^i); - i&^=2; - asInt(i|5); - isInt(i|5); - asInt(5|i); - isInt(5|i); - asInt(i|i); - isInt(i|i); - i|=2; - asInt(i^5); - isInt(i^5); - asInt(5^i); - isInt(5^i); - asInt(i^i); - isInt(i^i); - i^=2; - asInt(i<<4); - isInt(i<<4); - i<<=2; - asInt(i>>4); - isInt(i>>4); - i>>=2; - asInt(i); - isInt(i); - asInt(0); - asInt(Int(0)); - isInt(Int(0)); - i = 10; - asInt(*&i); - isInt(*&i); - asInt(23); - asInt(Int(f)); - isInt(Int(f)); + asInt(i) + isInt(i) + asInt(-i) + isInt(-i) + asInt(^i) + isInt(^i) + asInt(+i) + isInt(+i) + asInt(i + 1) + isInt(i + 1) + asInt(1 + i) + isInt(1 + i) + asInt(i + i) + isInt(i + i) + i++ + i += 1 + asInt(i - 1) + isInt(i - 1) + asInt(1 - i) + isInt(1 - i) + asInt(i - i) + isInt(i - i) + i-- + i -= 1 + asInt(i * 2) + isInt(i * 2) + asInt(2 * i) + isInt(2 * i) + asInt(i * i) + isInt(i * i) + i *= 2 + asInt(i / 5) + isInt(i / 5) + asInt(5 / i) + isInt(5 / i) + asInt(i / i) + isInt(i / i) + i /= 2 + asInt(i % 5) + isInt(i % 5) + asInt(5 % i) + isInt(5 % i) + asInt(i % i) + isInt(i % i) + i %= 2 + asInt(i & 5) + isInt(i & 5) + asInt(5 & i) + isInt(5 & i) + asInt(i & i) + isInt(i & i) + i &= 2 + asInt(i &^ 5) + isInt(i &^ 5) + asInt(5 &^ i) + isInt(5 &^ i) + asInt(i &^ i) + isInt(i &^ i) + i &^= 2 + asInt(i | 5) + isInt(i | 5) + asInt(5 | i) + isInt(5 | i) + asInt(i | i) + isInt(i | i) + i |= 2 + asInt(i ^ 5) + isInt(i ^ 5) + asInt(5 ^ i) + isInt(5 ^ i) + asInt(i ^ i) + isInt(i ^ i) + i ^= 2 + asInt(i << 4) + isInt(i << 4) + i <<= 2 + asInt(i >> 4) + isInt(i >> 4) + i >>= 2 + asInt(i) + isInt(i) + asInt(0) + asInt(Int(0)) + isInt(Int(0)) + i = 10 + asInt(*&i) + isInt(*&i) + asInt(23) + asInt(Int(f)) + isInt(Int(f)) - asMap(m); - isMap(m); - asMap(nil); - m = nil; - asMap(make(Map)); - isMap(make(Map)); - asMap(*&m); - isMap(*&m); - asMap(Map(nil)); - isMap(Map(nil)); - asMap(Map{}); - isMap(Map{}); + asMap(m) + isMap(m) + asMap(nil) + m = nil + asMap(make(Map)) + isMap(make(Map)) + asMap(*&m) + isMap(*&m) + asMap(Map(nil)) + isMap(Map(nil)) + asMap(Map{}) + isMap(Map{}) - asSlice(slice); - isSlice(slice); - asSlice(make(Slice, 5)); - isSlice(make(Slice, 5)); - asSlice([]byte{1,2,3}); - asSlice([]byte{1,2,3}[0:2]); - asSlice(slice[0:4]); - isSlice(slice[0:4]); - asSlice(slice[3:8]); - isSlice(slice[3:8]); - asSlice(nil); - asSlice(Slice(nil)); - isSlice(Slice(nil)); - slice = nil; - asSlice(Slice{1,2,3}); - isSlice(Slice{1,2,3}); - asSlice(Slice{}); - isSlice(Slice{}); - asSlice(*&slice); - isSlice(*&slice); + asSlice(slice) + isSlice(slice) + asSlice(make(Slice, 5)) + isSlice(make(Slice, 5)) + asSlice([]byte{1, 2, 3}) + asSlice([]byte{1, 2, 3}[0:2]) + asSlice(slice[0:4]) + isSlice(slice[0:4]) + asSlice(slice[3:8]) + isSlice(slice[3:8]) + asSlice(nil) + asSlice(Slice(nil)) + isSlice(Slice(nil)) + slice = nil + asSlice(Slice{1, 2, 3}) + isSlice(Slice{1, 2, 3}) + asSlice(Slice{}) + isSlice(Slice{}) + asSlice(*&slice) + isSlice(*&slice) - asString(str); - isString(str); - asString(str+"a"); - isString(str+"a"); - asString("a"+str); - isString("a"+str); - asString(str+str); - isString(str+str); - str += "a"; - str += str; - asString(String('a')); - isString(String('a')); - asString(String(slice)); - isString(String(slice)); - asString(String([]byte(nil))); - isString(String([]byte(nil))); - asString("hello"); - asString(String("hello")); - isString(String("hello")); - str = "hello"; - isString(str); - asString(*&str); - isString(*&str); + asString(str) + isString(str) + asString(str + "a") + isString(str + "a") + asString("a" + str) + isString("a" + str) + asString(str + str) + isString(str + str) + str += "a" + str += str + asString(String('a')) + isString(String('a')) + asString(String([]byte(slice))) + isString(String([]byte(slice))) + asString(String([]byte(nil))) + isString(String([]byte(nil))) + asString("hello") + asString(String("hello")) + isString(String("hello")) + str = "hello" + isString(str) + asString(*&str) + isString(*&str) } diff --git a/test/named1.go b/test/named1.go index 21019533c..241697d5c 100644 --- a/test/named1.go +++ b/test/named1.go @@ -12,46 +12,57 @@ package main type Bool bool type Map map[int]int + func (Map) M() {} -func asBool(Bool) {} +type Slice []byte + +var slice Slice + +func asBool(Bool) {} +func asString(String) {} + +type String string func main() { var ( - b Bool = true; - i, j int; - c = make(chan int); - m = make(Map); + b Bool = true + i, j int + c = make(chan int) + m = make(Map) ) - asBool(b); - asBool(!b); - asBool(true); - asBool(*&b); - asBool(Bool(true)); - asBool(1!=2); // ERROR "cannot use.*type bool.*as type Bool" - asBool(i < j); // ERROR "cannot use.*type bool.*as type Bool" + asBool(b) + asBool(!b) + asBool(true) + asBool(*&b) + asBool(Bool(true)) + asBool(1 != 2) // ERROR "cannot use.*type bool.*as type Bool" + asBool(i < j) // ERROR "cannot use.*type bool.*as type Bool" - _, b = m[2]; // ERROR "cannot .* bool.*type Bool" - m[2] = 1, b; // ERROR "cannot use.*type Bool.*as type bool" + _, b = m[2] // ERROR "cannot .* bool.*type Bool" + m[2] = 1, b // ERROR "cannot use.*type Bool.*as type bool" - b = c<-1; // ERROR "cannot use.*type bool.*type Bool" - _ = b; - asBool(c<-1); // ERROR "cannot use.*type bool.*as type Bool" + b = c <- 1 // ERROR "cannot use.*type bool.*type Bool" + _ = b + asBool(c <- 1) // ERROR "cannot use.*type bool.*as type Bool" - _, b = <-c; // ERROR "cannot .* bool.*type Bool" - _ = b; + _, b = <-c // ERROR "cannot .* bool.*type Bool" + _ = b - var inter interface{}; - _, b = inter.(Map); // ERROR "cannot .* bool.*type Bool" - _ = b; + var inter interface{} + _, b = inter.(Map) // ERROR "cannot .* bool.*type Bool" + _ = b - var minter interface{M()}; - _, b = minter.(Map); // ERROR "cannot .* bool.*type Bool" - _ = b; + var minter interface { + M() + } + _, b = minter.(Map) // ERROR "cannot .* bool.*type Bool" + _ = b - asBool(closed(c)); // ERROR "cannot use.*type bool.*as type Bool" - b = closed(c); // ERROR "cannot use.*type bool.*type Bool" - _ = b; -} + asBool(closed(c)) // ERROR "cannot use.*type bool.*as type Bool" + b = closed(c) // ERROR "cannot use.*type bool.*type Bool" + _ = b + asString(String(slice)) // ERROR "cannot convert slice" +} |