mirror of
https://github.com/golang/go.git
synced 2025-05-05 15:43:04 +00:00
cmd/compile: handle defined iter func type correctly
Fixed #64930 Change-Id: I916de7f97116fb20cb2f3f0b425ac34409afd494 Reviewed-on: https://go-review.googlesource.com/c/go/+/553436 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
This commit is contained in:
parent
1ae729e6d3
commit
881869dde0
@ -934,7 +934,7 @@ func (r *rewriter) endLoop(loop *forLoop) {
|
|||||||
if rfunc.Params().Len() != 1 {
|
if rfunc.Params().Len() != 1 {
|
||||||
base.Fatalf("invalid typecheck of range func")
|
base.Fatalf("invalid typecheck of range func")
|
||||||
}
|
}
|
||||||
ftyp := rfunc.Params().At(0).Type().(*types2.Signature) // func(...) bool
|
ftyp := types2.CoreType(rfunc.Params().At(0).Type()).(*types2.Signature) // func(...) bool
|
||||||
if ftyp.Results().Len() != 1 {
|
if ftyp.Results().Len() != 1 {
|
||||||
base.Fatalf("invalid typecheck of range func")
|
base.Fatalf("invalid typecheck of range func")
|
||||||
}
|
}
|
||||||
|
@ -311,6 +311,30 @@ func testcalls() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type iter3YieldFunc func(int, int) bool
|
||||||
|
|
||||||
|
func iter3(list ...int) func(iter3YieldFunc) {
|
||||||
|
return func(yield iter3YieldFunc) {
|
||||||
|
for k, v := range list {
|
||||||
|
if !yield(k, v) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func testcalls1() {
|
||||||
|
ncalls := 0
|
||||||
|
for k, v := range iter3(1, 2, 3) {
|
||||||
|
_, _ = k, v
|
||||||
|
ncalls++
|
||||||
|
}
|
||||||
|
if ncalls != 3 {
|
||||||
|
println("wrong number of calls:", ncalls, "!= 3")
|
||||||
|
panic("fail")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
testfunc0()
|
testfunc0()
|
||||||
testfunc1()
|
testfunc1()
|
||||||
@ -323,4 +347,5 @@ func main() {
|
|||||||
testfunc8()
|
testfunc8()
|
||||||
testfunc9()
|
testfunc9()
|
||||||
testcalls()
|
testcalls()
|
||||||
|
testcalls1()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user