Issue #3548 describes a bug in the compiler which was fixed by commit 505e50b. But this case wasn't covered by our current tests (obviously) and the fix in the compiler looks accidental so it's worth adding a test for it. Fixes #3548
This commit is contained in:
parent
ff7a9f9f9a
commit
e06a1163d0
35
_fixtures/issue3548.go
Normal file
35
_fixtures/issue3548.go
Normal file
@ -0,0 +1,35 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type Thing struct {
|
||||
str string
|
||||
}
|
||||
|
||||
func (d *Thing) Test() bool {
|
||||
return d != nil
|
||||
}
|
||||
|
||||
func callit(f func()) {
|
||||
f()
|
||||
}
|
||||
|
||||
func main() {
|
||||
cases := []struct {
|
||||
name string
|
||||
thing Thing
|
||||
}{
|
||||
{
|
||||
name: "Success",
|
||||
thing: Thing{str: "hello"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
callit(func() {
|
||||
fmt.Println("hello", c.thing.Test())
|
||||
})
|
||||
}
|
||||
}
|
@ -1722,3 +1722,23 @@ func TestBadUnsafePtr(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestCapturedVariable(t *testing.T) {
|
||||
// Checks that variables captured by a closure (that are not pointers) are
|
||||
// readable. See issue #3548.
|
||||
// This was broken in Go 1.21 due to a compiler bug.
|
||||
if goversion.VersionAfterOrEqual(runtime.Version(), 1, 21) && !goversion.VersionAfterOrEqual(runtime.Version(), 1, 22) {
|
||||
t.Skip("broken")
|
||||
}
|
||||
withTestProcess("issue3548", t, func(p *proc.Target, grp *proc.TargetGroup, fixture protest.Fixture) {
|
||||
setFileBreakpoint(p, t, fixture.Source, 32)
|
||||
assertNoError(grp.Continue(), t, "Continue()")
|
||||
v := evalVariable(p, t, "c")
|
||||
assertVariable(t, v, varTest{
|
||||
name: "c",
|
||||
preserveName: true,
|
||||
value: "struct { main.name string; main.thing main.Thing } {name: \"Success\", thing: main.Thing {str: \"hello\"}}",
|
||||
varType: "struct { main.name string; main.thing main.Thing }",
|
||||
})
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user