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: panic when duplicate verbs are found #1205

Merged
merged 1 commit into from
Apr 9, 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
7 changes: 7 additions & 0 deletions go-runtime/compile/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,13 @@ func visitFuncDecl(pctx *parseContext, node *ast.FuncDecl) (verb *schema.Verb, e
if !isVerb {
return nil, nil
}

for _, name := range pctx.nativeNames {
if name == node.Name.Name {
return nil, errorf(node, "verb %q already exported", node.Name.Name)
}
}

fnt := pctx.pkg.TypesInfo.Defs[node.Name].(*types.Func) //nolint:forcetypeassert
sig := fnt.Type().(*types.Signature) //nolint:forcetypeassert
if sig.Recv() != nil {
Expand Down
9 changes: 9 additions & 0 deletions go-runtime/compile/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,12 @@ func TestErrorReporting(t *testing.T) {
_, _, err := ExtractModuleSchema("testdata/failing")
assert.EqualError(t, err, filepath.Join(pwd, `testdata/failing/failing.go`)+`:14:2-46: call must have exactly three arguments`)
}

func TestDuplicateVerbNames(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
pwd, _ := os.Getwd()
_, _, err := ExtractModuleSchema("testdata/duplicateverbs")
assert.EqualError(t, err, filepath.Join(pwd, `testdata/duplicateverbs/duplicateverbs.go`)+`:23:1-2: verb "Time" already exported`)
}
25 changes: 25 additions & 0 deletions go-runtime/compile/testdata/duplicateverbs/duplicateverbs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package duplicateverbs

import (
"context"
"time"
)

type TimeRequest struct {
Name string
}
type TimeResponse struct {
Time time.Time
}

// Time returns the current time.
//
//ftl:export
func Time(ctx context.Context, req TimeRequest) (TimeResponse, error) {
return TimeResponse{Time: time.Now()}, nil
}

//ftl:export
func Time(ctx context.Context, req TimeRequest) (TimeResponse, error) {
return TimeResponse{Time: time.Now()}, nil
}
2 changes: 2 additions & 0 deletions go-runtime/compile/testdata/duplicateverbs/ftl.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module = "duplicateverbs"
language = "go"
45 changes: 45 additions & 0 deletions go-runtime/compile/testdata/duplicateverbs/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
module ftl/duplicateverbs

go 1.22.1

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

require github.com/TBD54566975/ftl v0.150.3

require (
connectrpc.com/connect v1.16.0 // indirect
connectrpc.com/grpcreflect v1.2.0 // indirect
connectrpc.com/otelconnect v0.7.0 // indirect
github.com/BurntSushi/toml v1.3.2 // indirect
github.com/TBD54566975/scaffolder v0.8.0 // indirect
github.com/alecthomas/concurrency v0.0.2 // indirect
github.com/alecthomas/kong v0.9.0 // indirect
github.com/alecthomas/participle/v2 v2.1.1 // indirect
github.com/alecthomas/types v0.13.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/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.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect
golang.org/x/mod v0.16.0 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
)
140 changes: 140 additions & 0 deletions go-runtime/compile/testdata/duplicateverbs/go.sum

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

Loading