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: treat type aliased subpackage types as underlying types #1564

Merged
merged 1 commit into from
May 23, 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
6 changes: 5 additions & 1 deletion go-runtime/compile/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -1267,7 +1267,11 @@ func visitType(pctx *parseContext, pos token.Pos, tnode types.Type, isExported b
switch underlying := tnode.Underlying().(type) {
case *types.Basic:
if named, ok := tnode.(*types.Named); ok {
return visitNamedRef(pctx, pos, named, isExported)
if !pctx.isPathInPkg(named.Obj().Pkg().Path()) {
// external named types get treated as refs
return visitNamedRef(pctx, pos, named, isExported)
}
// internal named types without decls are treated as basic types
}
switch underlying.Kind() {
case types.String:
Expand Down
20 changes: 20 additions & 0 deletions go-runtime/compile/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,26 @@ func TestExtractModuleSchemaNamedTypes(t *testing.T) {
assert.Equal(t, normaliseString(expected), normaliseString(actual.String()))
}

func TestExtractModuleSchemaParent(t *testing.T) {
prebuildTestModule(t, "testdata/parent")
if testing.Short() {
t.SkipNow()
}
r, err := ExtractModuleSchema("testdata/parent", &schema.Schema{})
assert.NoError(t, err)
assert.Equal(t, r.MustGet().Errors, nil, "expected no schema errors")
actual := schema.Normalise(r.MustGet().Module)
expected := `module parent {
export data ChildStruct {
name String?
}

export verb verb(Unit) parent.ChildStruct
}
`
assert.Equal(t, normaliseString(expected), normaliseString(actual.String()))
}

func TestParsedirectives(t *testing.T) {
tests := []struct {
name string
Expand Down
11 changes: 11 additions & 0 deletions go-runtime/compile/testdata/parent/child/child.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package child

import (
"github.com/TBD54566975/ftl/go-runtime/ftl" // Import the FTL SDK.
)

type ChildStruct struct {
Name ftl.Option[ChildAlias]
}

type ChildAlias string
2 changes: 2 additions & 0 deletions go-runtime/compile/testdata/parent/ftl.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module = "parent"
language = "go"
45 changes: 45 additions & 0 deletions go-runtime/compile/testdata/parent/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
module ftl/parent

go 1.22.2

toolchain go1.22.3

require github.com/TBD54566975/ftl v0.222.1

require (
connectrpc.com/connect v1.16.1 // indirect
connectrpc.com/grpcreflect v1.2.0 // indirect
connectrpc.com/otelconnect v0.7.0 // indirect
github.com/alecthomas/concurrency v0.0.2 // indirect
github.com/alecthomas/participle/v2 v2.1.1 // indirect
github.com/alecthomas/types v0.15.0 // indirect
github.com/alessio/shellescape v1.4.2 // indirect
github.com/danieljoos/wincred v1.2.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/pgx/v5 v5.5.5 // 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
github.com/swaggest/jsonschema-go v0.3.70 // indirect
github.com/swaggest/refl v1.3.0 // indirect
github.com/zalando/go-keyring v0.2.4 // indirect
go.opentelemetry.io/otel v1.26.0 // indirect
go.opentelemetry.io/otel/metric v1.26.0 // indirect
go.opentelemetry.io/otel/trace v1.26.0 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
google.golang.org/protobuf v1.34.1 // indirect
)

replace github.com/TBD54566975/ftl => ../../../..
136 changes: 136 additions & 0 deletions go-runtime/compile/testdata/parent/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions go-runtime/compile/testdata/parent/parent.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package parent

import (
"context"
// Import the FTL SDK.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: irrelevant comment

"ftl/parent/child"
)

//ftl:verb export
func Verb(ctx context.Context) (child.ChildStruct, error) {
return child.ChildStruct{}, nil
}
Loading