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/interface | |
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/interface')
-rw-r--r-- | test/interface/explicit.go | 41 | ||||
-rw-r--r-- | test/interface/pointer.go | 16 | ||||
-rw-r--r-- | test/interface/receiver1.go | 71 |
3 files changed, 74 insertions, 54 deletions
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 } - |