Skip to content

Commit

Permalink
fix: handle range on chan function return
Browse files Browse the repository at this point in the history
  • Loading branch information
nrwiersma committed Jun 3, 2020
1 parent 151a856 commit 2de0c80
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
21 changes: 21 additions & 0 deletions _test/range7.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package main

import (
"fmt"
)

func someChan() <-chan struct{} {
c := make(chan struct{}, 1)
c <- struct{}{}
return c
}

func main() {
for _ = range someChan() {
fmt.Println("success")
return
}
}

// Output:
// success
3 changes: 3 additions & 0 deletions interp/scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ func (s *scope) rangeChanType(n *node) *itype {
return t
}
}
if c := n.child[1]; c.typ != nil && c.typ.cat == chanT {
return c.typ
}
return nil
}

Expand Down

0 comments on commit 2de0c80

Please sign in to comment.