-
Notifications
You must be signed in to change notification settings - Fork 8
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
fix: avoid duplicate import aliases #2502
Conversation
0006a28
to
a0cd423
Compare
// returns the import path and directory name for an external type | ||
// package and directory names are the same (dir=bar, pkg=bar): "github.com/foo/bar.A" => "github.com/foo/bar", none | ||
// package and directory names differ (dir=bar, pkg=baz): "github.com/foo/bar.baz.A" => "github.com/foo/bar", "baz" | ||
func goImportFromQualifiedName(qualifiedName string) (importPath string, directoryName optional.Option[string], err error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, named return signature helps heaps with readability in this case.
go-runtime/compile/build.go
Outdated
} | ||
|
||
case *schema.TypeAlias: | ||
if !aliasesMustBeExported || n.IsExported() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure about the context here, so I'm probably wrong here, but thought I'd flag it in case.
Reading this if statement makes me think this block is for exported aliases, but its checking for when aliases must not be exported? Should it be aliasesMustBeExported || n.IsExported()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think what I want is:
if aliasesMustBeExported && !n.IsExported() {
// early exit
}
When i wrote the original line, it also struck me as odd / confusing, so I'll replace it with the above as it's a lot clearer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
# Conflicts: # go-runtime/compile/build.go
82cbce9
to
67d63ce
Compare
fixes #2469
When scaffolding imports for external go packages, FTL will use the shortest unique part of the path as the alias. This allows package aliases to have neat and expected aliases in simple cases, and falling back to the next best option as conflicts arise.
For example: