aboutsummaryrefslogtreecommitdiffstats
path: root/testdata/struct_reference.go
diff options
context:
space:
mode:
authorTeddy Wing2024-03-09 20:58:56 +0100
committerTeddy Wing2024-03-09 20:58:56 +0100
commitf923099c4302e49a1563183c5217e1e5cf017d85 (patch)
treecb52685aa7bcc7e917ebc1d67ca0e7f3276dc130 /testdata/struct_reference.go
parentbf64f32a1a8099ee45d66796b5f60f9ae10a2436 (diff)
downloadgocapturedrefrace-f923099c4302e49a1563183c5217e1e5cf017d85.tar.bz2
Try checking if the same variable in inner scope is in parent scope
Can't figure out how to resolve the `funcScope != scope` problem in Go 1.22. Saw the `Names` method in the documentation and out of curiosity tried to see if that could be used as an alternate means of checking if a variable is declared in the parent scope. Turns out I get a bunch of false positives with that so I can't use it: $ go test -v === RUN Test identifier: &ast.Ident{NamePos:4069121, Name:"copied", Obj:(*ast.Object)(0x1400206b720)}, obj: &ast.Object{Kind:4, Name:"copied", Decl:(*ast.Field)(0x140067420c0), Data:interface {}(nil), Type:interface {}(nil)}, decl: &ast.Field{Doc:(*ast.CommentGroup)(nil), Names:[]*ast.Ident{(*ast.Ident)(0x1400215fea0)}, Type:(*ast.Ident)(0x1400215fec0), Tag:(*ast.BasicLit)(nil), Comment:(*ast.CommentGroup)(nil)} scope: &types.Scope{parent:(*types.Scope)(0x14002164960), children:[]*types.Scope{(*types.Scope)(0x14003b12d80)}, number:1, elems:map[string]types.Object{"capturedReference":(*types.Var)(0x14003b12c60), "capturedReference2":(*types.Var)(0x14003b12cc0), "copied":(*types.Var)(0x14003b12d20)}, pos:4069035, end:4069588, comment:"function", isFunc:true} Names: []string{"capturedReference", "capturedReference2", "copied"} funcScope: &types.Scope{parent:(*types.Scope)(0x14002165620), children:[]*types.Scope{(*types.Scope)(0x14003b12ea0)}, number:1, elems:map[string]types.Object{"copied":(*types.Var)(0x14003b12e40), "decl":(*types.Var)(0x14003b13020), "newVar":(*types.Var)(0x14003b12f60), "str":(*types.Var)(0x14003b12fc0)}, pos:4069116, end:4069578, comment:"function", isFunc:true} Names: []string{"copied", "decl", "newVar", "str"} identifier: &ast.Ident{NamePos:4069325, Name:"copied", Obj:(*ast.Object)(0x1400206b720)}, obj: &ast.Object{Kind:4, Name:"copied", Decl:(*ast.Field)(0x140067420c0), Data:interface {}(nil), Type:interface {}(nil)}, decl: &ast.Field{Doc:(*ast.CommentGroup)(nil), Names:[]*ast.Ident{(*ast.Ident)(0x1400215fea0)}, Type:(*ast.Ident)(0x1400215fec0), Tag:(*ast.BasicLit)(nil), Comment:(*ast.CommentGroup)(nil)} scope: &types.Scope{parent:(*types.Scope)(0x14002165620), children:[]*types.Scope{(*types.Scope)(0x14003b12ea0)}, number:1, elems:map[string]types.Object{"copied":(*types.Var)(0x14003b12e40), "decl":(*types.Var)(0x14003b13020), "newVar":(*types.Var)(0x14003b12f60), "str":(*types.Var)(0x14003b12fc0)}, pos:4069116, end:4069578, comment:"function", isFunc:true} Names: []string{"copied", "decl", "newVar", "str"} funcScope: &types.Scope{parent:(*types.Scope)(0x14002165620), children:[]*types.Scope{(*types.Scope)(0x14003b12ea0)}, number:1, elems:map[string]types.Object{"copied":(*types.Var)(0x14003b12e40), "decl":(*types.Var)(0x14003b13020), "newVar":(*types.Var)(0x14003b12f60), "str":(*types.Var)(0x14003b12fc0)}, pos:4069116, end:4069578, comment:"function", isFunc:true} Names: []string{"copied", "decl", "newVar", "str"} analysistest.go:522: gocapturedrefrace/testdata/shadow.go:38:6: unexpected diagnostic: captured reference err in goroutine closure analysistest.go:522: gocapturedrefrace/testdata/shadow.go:39:14: unexpected diagnostic: captured reference err in goroutine closure analysistest.go:522: gocapturedrefrace/testdata/shadow.go:47:3: unexpected diagnostic: captured reference err in goroutine closure analysistest.go:522: gocapturedrefrace/testdata/shadow.go:48:6: unexpected diagnostic: captured reference err in goroutine closure analysistest.go:522: gocapturedrefrace/testdata/shadow.go:49:14: unexpected diagnostic: captured reference err in goroutine closure analysistest.go:522: gocapturedrefrace/testdata/shadow.go:66:3: unexpected diagnostic: captured reference err1 in goroutine closure analysistest.go:522: gocapturedrefrace/testdata/shadow.go:67:3: unexpected diagnostic: captured reference err2 in goroutine closure analysistest.go:522: gocapturedrefrace/testdata/shadow.go:68:6: unexpected diagnostic: captured reference err1 in goroutine closure analysistest.go:522: gocapturedrefrace/testdata/shadow.go:68:21: unexpected diagnostic: captured reference err2 in goroutine closure analysistest.go:522: gocapturedrefrace/testdata/shadow.go:69:14: unexpected diagnostic: captured reference err1 in goroutine closure analysistest.go:522: gocapturedrefrace/testdata/shadow.go:69:20: unexpected diagnostic: captured reference err2 in goroutine closure analysistest.go:522: gocapturedrefrace/testdata/simple.go:29:10: unexpected diagnostic: captured reference copied in goroutine closure analysistest.go:522: gocapturedrefrace/testdata/simple.go:32:3: unexpected diagnostic: captured reference copied in goroutine closure analysistest.go:522: gocapturedrefrace/testdata/simple.go:39:3: unexpected diagnostic: captured reference newVar in goroutine closure analysistest.go:522: gocapturedrefrace/testdata/simple.go:42:18: unexpected diagnostic: captured reference str in goroutine closure analysistest.go:522: gocapturedrefrace/testdata/simple.go:45:3: unexpected diagnostic: captured reference decl in goroutine closure analysistest.go:522: gocapturedrefrace/testdata/simple.go:46:18: unexpected diagnostic: captured reference decl in goroutine closure analysistest.go:522: gocapturedrefrace/testdata/simple.go:57:10: unexpected diagnostic: captured reference s in goroutine closure analysistest.go:522: gocapturedrefrace/testdata/simple.go:58:3: unexpected diagnostic: captured reference s in goroutine closure --- FAIL: Test (0.40s) FAIL exit status 1 FAIL gopkg.teddywing.com/capturedrefrace 0.414s
Diffstat (limited to 'testdata/struct_reference.go')
0 files changed, 0 insertions, 0 deletions