Skip to content

Commit

Permalink
fix: Unit now works correctly in Go
Browse files Browse the repository at this point in the history
  • Loading branch information
alecthomas committed Jan 15, 2024
1 parent 0ea09c3 commit 7223c9a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 3 additions & 1 deletion backend/schema/protobuf_dec.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ func typeToSchema(s *schemapb.Type) Type {
return mapToSchema(s.Map)
case *schemapb.Type_Optional:
return &Optional{Pos: posFromProto(s.Optional.Pos), Type: typeToSchema(s.Optional.Type)}
case *schemapb.Type_Unit:
return &Unit{Pos: posFromProto(s.Unit.Pos)}
}
panic("unreachable")
panic(fmt.Sprintf("unhandled type: %T", s.Value))
}

func metadataListToSchema(s []*schemapb.Metadata) []Metadata {
Expand Down
2 changes: 1 addition & 1 deletion backend/schema/protobuf_enc.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,5 @@ func typeToProto(t Type) *schemapb.Type {
case *Optional:
return &schemapb.Type{Value: &schemapb.Type_Optional{Optional: t.ToProto().(*schemapb.Optional)}}
}
panic("unreachable")
panic(fmt.Sprintf("unhandled type: %T", t))
}
7 changes: 5 additions & 2 deletions go-runtime/compile/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func visitFuncDecl(pctx *parseContext, node *ast.FuncDecl) (verb *schema.Verb, e
}
var req schema.Type
if reqt != nil {
req, err = parseStruct(pctx, node, params.At(1).Type())
req, err = parseType(pctx, node, params.At(1).Type())
if err != nil {
return nil, err
}
Expand All @@ -268,7 +268,7 @@ func visitFuncDecl(pctx *parseContext, node *ast.FuncDecl) (verb *schema.Verb, e
}
var resp schema.Type
if respt != nil {
resp, err = parseStruct(pctx, node, results.At(0).Type())
resp, err = parseType(pctx, node, results.At(0).Type())
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -405,6 +405,9 @@ func parseType(pctx *parseContext, node ast.Node, tnode types.Type) (schema.Type
case "time.Time":
return &schema.Time{Pos: goPosToSchemaPos(node.Pos())}, nil

case "github.com/TBD54566975/ftl/go-runtime/sdk.Unit":
return &schema.Unit{Pos: goPosToSchemaPos(node.Pos())}, nil

case "github.com/TBD54566975/ftl/go-runtime/sdk.Option":
underlying, err := parseType(pctx, node, named.TypeArgs().At(0))
if err != nil {
Expand Down

0 comments on commit 7223c9a

Please sign in to comment.