aboutsummaryrefslogtreecommitdiff
path: root/test/named1.go
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
commit565b5dc0760baf556f83adf847f578718a1c571f (patch)
treee2dc094314df75a900a88adc71677452545d74ca /test/named1.go
parent6aaef044698bf9da21e270188f281321de98a391 (diff)
downloadgo-565b5dc0760baf556f83adf847f578718a1c571f.tar.gz
go-565b5dc0760baf556f83adf847f578718a1c571f.zip
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 #840. Fixes #830. Fixes #778. R=ken2 CC=golang-dev https://golang.org/cl/1303042
Diffstat (limited to 'test/named1.go')
-rw-r--r--test/named1.go69
1 files changed, 40 insertions, 29 deletions
diff --git a/test/named1.go b/test/named1.go
index 21019533ce..241697d5c0 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"
+}