Skip to content

Commit

Permalink
proc: add regression test for issue #3548 (#3553)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
aarzilli authored Nov 4, 2023
1 parent ff7a9f9 commit e06a116
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
35 changes: 35 additions & 0 deletions _fixtures/issue3548.go
Original file line number Diff line number Diff line change
@@ -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())
})
}
}
20 changes: 20 additions & 0 deletions pkg/proc/variables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }",
})
})
}

0 comments on commit e06a116

Please sign in to comment.