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

fix: handle custom local names for widened types #2401

Merged
merged 3 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions go-runtime/schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ func TestExtractModuleSchemaTwo(t *testing.T) {
}
actual := schema.Normalise(r.Module)
expected := `module two {
typealias BackoffAlias Any
+typemap go "github.com/jpillora/backoff.Backoff"

typealias ExplicitAliasAlias Any
+typemap kotlin "com.foo.bar.NonFTLType"
+typemap go "github.com/TBD54566975/ftl/go-runtime/schema/testdata.lib.NonFTLType"
Expand Down
6 changes: 4 additions & 2 deletions go-runtime/schema/testdata/two/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ go 1.22.2

replace github.com/TBD54566975/ftl => ../../../..

require github.com/TBD54566975/ftl v0.150.3
require (
github.com/TBD54566975/ftl v0.150.3
github.com/jpillora/backoff v1.0.0
)

require (
connectrpc.com/connect v1.16.2 // indirect
Expand All @@ -26,7 +29,6 @@ require (
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/pgx/v5 v5.6.0 // indirect
github.com/jackc/puddle/v2 v2.2.1 // indirect
github.com/jpillora/backoff v1.0.0 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/multiformats/go-base36 v0.2.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go-runtime/schema/testdata/two/two.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/TBD54566975/ftl/go-runtime/ftl"
lib "github.com/TBD54566975/ftl/go-runtime/schema/testdata"
libbackoff "github.com/jpillora/backoff"

"ftl/builtin"
)
Expand Down Expand Up @@ -103,6 +104,9 @@ type TransitiveAliasAlias = lib.NonFTLType

type TransitiveAlias lib.NonFTLType

//ftl:typealias
type BackoffAlias libbackoff.Backoff

func transitiveVerbCall(ctx context.Context, req Payload[string]) error {
_, err := ftl.Call(ctx, Two, req)
if err != nil {
Expand Down
20 changes: 9 additions & 11 deletions go-runtime/schema/typealias/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,14 @@ func qualifiedNameFromSelectorExpr(pass *analysis.Pass, node ast.Node) string {
if !ok {
return ""
}
for _, im := range pass.Pkg.Imports() {
if im.Name() != ident.Name {
continue
}
fqName := im.Path()
if parts := strings.Split(im.Path(), "/"); parts[len(parts)-1] != ident.Name {
// if package differs from the directory name, add the package name to the fqName
fqName = fqName + "." + ident.Name
}
return fqName + "." + se.Sel.Name
pkgName, ok := pass.TypesInfo.ObjectOf(ident).(*types.PkgName)
if !ok {
return ""
}
fqName := pkgName.Imported().Path()
if parts := strings.Split(fqName, "/"); parts[len(parts)-1] != pkgName.Imported().Name() {
// if package differs from the directory name, add the package name to the fqName
fqName = fqName + "." + ident.Name
}
return ""
return fqName + "." + se.Sel.Name
}
Loading