From: Matthew Dempsky Date: Fri, 1 Jan 2021 12:51:22 +0000 (-0800) Subject: [dev.regabi] test: add another closure test case X-Git-Tag: go1.17beta1~1539^2~153 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=bfa97ba48f;p=gostls13.git [dev.regabi] test: add another closure test case When deciding whether a captured variable can be passed by value, the compiler is sensitive to the order that the OCLOSURE node is typechecked relative to the order that the variable is passed to "checkassign". Today, for an assignment like: q, g = 2, func() int { return q } we get this right because we always typecheck the full RHS expression list before calling checkassign on any LHS expression. But I nearly made a change that would interleave this ordering, causing us to call checkassign on q before typechecking the function literal. And alarmingly, there weren't any tests that caught this. So this commit adds one. Change-Id: I66cacd61066c7a229070861a7d973bcc434904cc Reviewed-on: https://go-review.googlesource.com/c/go/+/280998 Trust: Matthew Dempsky Run-TryBot: Matthew Dempsky TryBot-Result: Go Bot Reviewed-by: Cuong Manh Le --- diff --git a/test/closure2.go b/test/closure2.go index e4db05d884..812d41f8ce 100644 --- a/test/closure2.go +++ b/test/closure2.go @@ -9,6 +9,8 @@ package main +var never bool + func main() { { type X struct { @@ -115,4 +117,16 @@ func main() { panic("g() != 2") } } + + { + var g func() int + q := 0 + q, g = 1, func() int { return q } + if never { + g = func() int { return 2 } + } + if g() != 1 { + panic("g() != 1") + } + } }