Skip to content

Commit

Permalink
fix: no longer projecting int64 to FTL Int (#1935)
Browse files Browse the repository at this point in the history
fixes #1920

`int64` no longer projected to the FTL Int data type; `int` must be used
instead.
  • Loading branch information
jonathanj-square authored Jul 8, 2024
1 parent f5c2bfa commit eb35da9
Show file tree
Hide file tree
Showing 25 changed files with 130 additions and 68 deletions.
10 changes: 5 additions & 5 deletions backend/controller/dal/testdata/go/fsm/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ require (
github.com/alecthomas/repr v0.4.0 // indirect
github.com/alecthomas/types v0.16.0 // indirect
github.com/alessio/shellescape v1.4.2 // indirect
github.com/aws/aws-sdk-go-v2 v1.30.0 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.12 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.12 // indirect
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.31.1 // indirect
github.com/aws/smithy-go v1.20.2 // indirect
github.com/aws/aws-sdk-go-v2 v1.30.1 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.13 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.13 // indirect
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.32.1 // indirect
github.com/aws/smithy-go v1.20.3 // indirect
github.com/benbjohnson/clock v1.3.5 // indirect
github.com/danieljoos/wincred v1.2.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
Expand Down
5 changes: 5 additions & 0 deletions backend/controller/dal/testdata/go/fsm/go.sum

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

10 changes: 5 additions & 5 deletions backend/controller/leases/testdata/go/leases/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ require (
github.com/alecthomas/repr v0.4.0 // indirect
github.com/alecthomas/types v0.16.0 // indirect
github.com/alessio/shellescape v1.4.2 // indirect
github.com/aws/aws-sdk-go-v2 v1.30.0 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.12 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.12 // indirect
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.31.1 // indirect
github.com/aws/smithy-go v1.20.2 // indirect
github.com/aws/aws-sdk-go-v2 v1.30.1 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.13 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.13 // indirect
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.32.1 // indirect
github.com/aws/smithy-go v1.20.3 // indirect
github.com/benbjohnson/clock v1.3.5 // indirect
github.com/danieljoos/wincred v1.2.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
Expand Down
5 changes: 5 additions & 0 deletions backend/controller/leases/testdata/go/leases/go.sum

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

13 changes: 13 additions & 0 deletions buildengine/discover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,19 @@ func TestDiscoverModules(t *testing.T) {
Watch: []string{"**/*.go", "go.mod", "go.sum", "../../../go-runtime/ftl/**/*.go"},
},
},
{
Config: moduleconfig.ModuleConfig{
Dir: "testdata/integer",
Language: "go",
Realm: "home",
Module: "integer",
Deploy: []string{"main"},
DeployDir: ".ftl",
Schema: "schema.pb",
Errors: "errors.pb",
Watch: []string{"**/*.go", "go.mod", "go.sum"},
},
},
{
Config: moduleconfig.ModuleConfig{
Dir: "testdata/other",
Expand Down
16 changes: 16 additions & 0 deletions buildengine/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,19 @@ func TestCycleDetection(t *testing.T) {
assert.Error(t, err)
assert.Contains(t, err.Error(), "detected a module dependency cycle that impacts these modules:")
}

func TestInt64BuildError(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
ctx := log.ContextWithNewDefaultLogger(context.Background())
engine, err := buildengine.New(ctx, nil, t.TempDir(), []string{"testdata/integer"})
assert.NoError(t, err)

defer engine.Close()

err = engine.Build(ctx)
assert.Error(t, err)
assert.Contains(t, err.Error(), `unsupported type "int64" for field "Input"`)
assert.Contains(t, err.Error(), `unsupported type "int64" for field "Output"`)
}
2 changes: 2 additions & 0 deletions buildengine/testdata/integer/ftl.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module = "integer"
language = "go"
7 changes: 7 additions & 0 deletions buildengine/testdata/integer/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module ftl/integer

go 1.22.2

toolchain go1.22.4

replace github.com/TBD54566975/ftl => /Users/jonathanj/dev/ftl
Empty file.
18 changes: 18 additions & 0 deletions buildengine/testdata/integer/integer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package integer

import (
"context"
)

type EchoRequest struct {
Input int64 `json:"value"`
}

type EchoResponse struct {
Output int64 `json:"value"`
}

//ftl:verb
func Echo(ctx context.Context, req EchoRequest) (EchoResponse, error) {
return EchoResponse{Output: req.Input}, nil
}
5 changes: 3 additions & 2 deletions go-runtime/compile/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -1240,13 +1240,14 @@ func visitConst(pctx *parseContext, cnode *types.Const) optional.Option[schema.V
}
return optional.Some[schema.Value](&schema.StringValue{Pos: goPosToSchemaPos(cnode.Pos()), Value: value})

case types.Int, types.Int64:
case types.Int:
value, err := strconv.ParseInt(cnode.Val().String(), 10, 64)
if err != nil {
pctx.errors.add(tokenWrapf(cnode.Pos(), cnode.Val().String(), err, "unsupported int constant"))
return optional.None[schema.Value]()
}
return optional.Some[schema.Value](&schema.IntValue{Pos: goPosToSchemaPos(cnode.Pos()), Value: int(value)})

default:
return optional.None[schema.Value]()
}
Expand Down Expand Up @@ -1284,7 +1285,7 @@ func visitType(pctx *parseContext, pos token.Pos, tnode types.Type, isExported b
case types.String:
return optional.Some[schema.Type](&schema.String{Pos: goPosToSchemaPos(pos)})

case types.Int, types.Int64:
case types.Int:
return optional.Some[schema.Type](&schema.Int{Pos: goPosToSchemaPos(pos)})

case types.Bool:
Expand Down
1 change: 0 additions & 1 deletion go-runtime/compile/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ func TestExtractModuleSchema(t *testing.T) {
export data Req {
int Int
int64 Int
float Float
string String
slice [String]
Expand Down
1 change: 0 additions & 1 deletion go-runtime/compile/testdata/one/one.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ func (WithoutDirectiveStruct) privateEnum() {}

type Req struct {
Int int
Int64 int64
Float float64
String string
Slice []string
Expand Down
10 changes: 5 additions & 5 deletions go-runtime/ftl/ftltest/testdata/go/pubsub/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ require (
github.com/alecthomas/repr v0.4.0 // indirect
github.com/alecthomas/types v0.16.0 // indirect
github.com/alessio/shellescape v1.4.2 // indirect
github.com/aws/aws-sdk-go-v2 v1.30.0 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.12 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.12 // indirect
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.31.1 // indirect
github.com/aws/smithy-go v1.20.2 // indirect
github.com/aws/aws-sdk-go-v2 v1.30.1 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.13 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.13 // indirect
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.32.1 // indirect
github.com/aws/smithy-go v1.20.3 // indirect
github.com/benbjohnson/clock v1.3.5 // indirect
github.com/danieljoos/wincred v1.2.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
Expand Down
5 changes: 5 additions & 0 deletions go-runtime/ftl/ftltest/testdata/go/pubsub/go.sum

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

10 changes: 5 additions & 5 deletions go-runtime/ftl/ftltest/testdata/go/subscriber/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ require (
github.com/alecthomas/repr v0.4.0 // indirect
github.com/alecthomas/types v0.16.0 // indirect
github.com/alessio/shellescape v1.4.2 // indirect
github.com/aws/aws-sdk-go-v2 v1.30.0 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.12 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.12 // indirect
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.31.1 // indirect
github.com/aws/smithy-go v1.20.2 // indirect
github.com/aws/aws-sdk-go-v2 v1.30.1 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.13 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.13 // indirect
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.32.1 // indirect
github.com/aws/smithy-go v1.20.3 // indirect
github.com/benbjohnson/clock v1.3.5 // indirect
github.com/danieljoos/wincred v1.2.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
Expand Down
Loading

0 comments on commit eb35da9

Please sign in to comment.