Skip to content

go/types,cmd/compile/internal/types2: type instantiation fails to distinguish similarly named defined types within a package #46592

@mdempsky

Description

@mdempsky

This program is invalid, but go/types returns success for type checking it: https://go2goplay.golang.org/p/F-SWVR4f2dN (Note: The go2go diagnostic is only produced if/after type checking succeeded; contrast https://go2goplay.golang.org/p/o5NZXojNhMX.)

This appears to be because the string produced by instantiatedHash doesn't distinguish package-scope defined types from function-scope defined ones. In CL 324573, I've workaround around this by hacking writeTypeName to include TypeName.Pos when writing type names for instiantiatedHash:

https://go-review.googlesource.com/c/go/+/324573/8/src/cmd/compile/internal/types2/subst.go
https://go-review.googlesource.com/c/go/+/324573/8/src/cmd/compile/internal/types2/typestring.go

With that change, unified IR is able to successfully compile this test case that exercises a bunch of nested type parameters and similarly named defined types: https://go-review.googlesource.com/c/go/+/324573/8/test/typeparam/nested.go

/cc @griesemer @findleyr

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions