Skip to content

compiler: disambiguate function-local named types#5336

Open
jakebailey wants to merge 3 commits intotinygo-org:devfrom
jakebailey:fix-5180
Open

compiler: disambiguate function-local named types#5336
jakebailey wants to merge 3 commits intotinygo-org:devfrom
jakebailey:fix-5180

Conversation

@jakebailey
Copy link
Copy Markdown
Member

Fixes #5180

This is an alternative to #5183 which handles more cases.

This is really tricky and I think only possible through the more complicated method in this PR, where we have to walk through more stuff to assign names where needed. As far as I can tell, this works even with build caching, but obviously comes at a cost.

I recommend looking just at the last commit, as that's the one that shows the change including how test golden files get updated.

@jakebailey jakebailey requested review from aykevl and dgryski April 21, 2026 18:32
Copy link
Copy Markdown
Member

@dgryski dgryski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. Handles generics (which my PR didn't). One more sign off from @niaow and/or @aykevl and can merge this.

Comment thread compiler/interface.go
Copy link
Copy Markdown
Member

@aykevl aykevl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't do a full review but here are some notes.

Comment thread compiler/compiler.go
pkg *types.Package
packageDir string // directory for this package
runtimePkg *types.Package
localTypeNames map[*types.TypeName]string
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you looked at typeutil.Map? It might do exactly what you want with much less complexity.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I just didn't think it really added much, because all it does is store the type, which we then just .Obj() on, so doesn't really do anything?

Comment thread compiler/interface.go
Comment on lines +710 to +711
// Names depend only on intrinsic SSA properties (RelString and the
// raw token.Pos used as a sort key), so any package compiling the
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To clarify: token.Pos is not used to uniquely identify a type, it is only used for sorting?
Asking since some things (like CGo) might not produce unique locations.

Copy link
Copy Markdown
Member Author

@jakebailey jakebailey Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, it is not, though I thought cgo was not supported in tinygo?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

type assertion resolving to wrong type

3 participants