Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unused: marking all fields as read doesn't work recursively #1249

Closed
dominikh opened this issue Apr 11, 2022 · 0 comments
Closed

unused: marking all fields as read doesn't work recursively #1249

dominikh opened this issue Apr 11, 2022 · 0 comments
Labels
false-positive started Issues we've started working on

Comments

@dominikh
Copy link
Owner

Some operations mark all fields in a struct as used, because we can't do any better. One example is converting to unsafe.Pointer – who knows what the user will do with the data afterwards.

Unfortunately, we're only marking the immediate fields as used:

type t struct {
	a, b int
	c    t2
}

type t2 struct {
	d, e int
}

func Foo() {
	var x t
	_ = unsafe.Pointer(&x)
}
$ run-dev-staticcheck baz.go
baz.go:11:2: field d is unused (U1000)
baz.go:11:5: field e is unused (U1000)

Fields d and e should also be marked as used, as they are part of t's memory layout. The same problem occurs for embedded fields.

@dominikh dominikh added false-positive started Issues we've started working on labels Apr 11, 2022
@dominikh dominikh added started Issues we've started working on and removed started Issues we've started working on labels Jun 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
false-positive started Issues we've started working on
Projects
None yet
Development

No branches or pull requests

1 participant