]> Cypherpunks repositories - gostls13.git/commitdiff
reflect: set dir when creating a channel via ChanOf
authorMichael Fraenkel <michael.fraenkel@gmail.com>
Fri, 2 Jan 2015 02:38:12 +0000 (21:38 -0500)
committerIan Lance Taylor <iant@golang.org>
Sun, 4 Jan 2015 19:42:14 +0000 (19:42 +0000)
Fixes #9135

Change-Id: I4d0e4eb52a3d64262f107eb7eae4096a6e47ac08
Reviewed-on: https://go-review.googlesource.com/2238
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/reflect/all_test.go
src/reflect/type.go

index 974b5d2f6c1e1b511da92a2c1e6db2fef9cb5234..278848bc007811dcbdbdf90daca4228230691acb 100644 (file)
@@ -3487,6 +3487,26 @@ func TestChanOf(t *testing.T) {
        checkSameType(t, Zero(ChanOf(BothDir, TypeOf(T1(1)))).Interface(), (chan T1)(nil))
 }
 
+func TestChanOfDir(t *testing.T) {
+       // check construction and use of type not in binary
+       type T string
+       crt := ChanOf(RecvDir, TypeOf(T("")))
+       cst := ChanOf(SendDir, TypeOf(T("")))
+
+       // check that type already in binary is found
+       type T1 int
+       checkSameType(t, Zero(ChanOf(RecvDir, TypeOf(T1(1)))).Interface(), (<-chan T1)(nil))
+       checkSameType(t, Zero(ChanOf(SendDir, TypeOf(T1(1)))).Interface(), (chan<- T1)(nil))
+
+       // check String form of ChanDir
+       if crt.ChanDir().String() != "<-chan" {
+               t.Errorf("chan dir: have %q, want %q", crt.ChanDir().String(), "<-chan")
+       }
+       if cst.ChanDir().String() != "chan<-" {
+               t.Errorf("chan dir: have %q, want %q", cst.ChanDir().String(), "chan<-")
+       }
+}
+
 func TestChanOfGC(t *testing.T) {
        done := make(chan bool, 1)
        go func() {
index 75d73adbca9be252e6c1b0b6368ac6c6e77bbd8e..d19e5f97674249e6b80733a2e0554939c343ea02 100644 (file)
@@ -1425,6 +1425,7 @@ func ChanOf(dir ChanDir, t Type) Type {
        prototype := *(**chanType)(unsafe.Pointer(&ichan))
        ch := new(chanType)
        *ch = *prototype
+       ch.dir = uintptr(dir)
        ch.string = &s
        ch.hash = fnv1(typ.hash, 'c', byte(dir))
        ch.elem = typ