Skip to content

unused: false positive involving unnamed struct types, named struct types and implicit conversions #810

@kylrth

Description

@kylrth

I discovered this while using the unused linter in golangci-lint. I hope I found the right place to report this issue. 🤞

Here's some code that reproduces it:

package unused_test

import "fmt"

type Thing struct {
	stuff int
	has   struct {
		a bool
		b bool
	}
}

func ExampleThing() {
	type temp struct {
		a bool
		b bool
	}

	stuff := map[string]Thing{
		"hello": {has: temp{true, false}},
	}

	fmt.Println(stuff["hello"].stuff, stuff["hello"].has)
	// Output: 0 {true false}
}

Running ./golangci-lint run unused_test.go results in unused_test.go:14:7: type `temp` is unused (unused).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions