From bb9a9f8c04222b0dc6de134e83d63970d3247abd Mon Sep 17 00:00:00 2001 From: Matt Toohey Date: Thu, 16 May 2024 14:53:47 +1000 Subject: [PATCH] fix sumtype checks --- backend/controller/console.go | 2 +- backend/controller/ingress/alias.go | 2 ++ go-runtime/compile/schema.go | 39 ++++++++++++++++------------- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/backend/controller/console.go b/backend/controller/console.go index 1a7288f761..7adacd2e9f 100644 --- a/backend/controller/console.go +++ b/backend/controller/console.go @@ -145,7 +145,7 @@ func (c *ConsoleService) GetModules(ctx context.Context, req *connect.Request[pb Config: c, }) - case *schema.Database, *schema.Enum, *schema.FSM: + case *schema.Database, *schema.Enum, *schema.TypeAlias, *schema.FSM: } } diff --git a/backend/controller/ingress/alias.go b/backend/controller/ingress/alias.go index 7f3048135a..de1f0191f7 100644 --- a/backend/controller/ingress/alias.go +++ b/backend/controller/ingress/alias.go @@ -59,6 +59,8 @@ func transformAliasedFields(sch *schema.Schema, t schema.Type, obj any, aliaser } } } + case *schema.TypeAlias: + return transformAliasedFields(sch, decl.Type, obj, aliaser) case *schema.Config, *schema.Database, *schema.FSM, *schema.Secret, *schema.Verb: return fmt.Errorf("%s: unsupported ref type %T", t.Pos, decl) } diff --git a/go-runtime/compile/schema.go b/go-runtime/compile/schema.go index a548cde584..3a8c8e10d1 100644 --- a/go-runtime/compile/schema.go +++ b/go-runtime/compile/schema.go @@ -1204,7 +1204,7 @@ func visitType(pctx *parseContext, pos token.Pos, tnode types.Type, isExported b Module: pctx.module.Name, Name: strcase.ToUpperCamel(named.Obj().Name()), }) - case *schema.Data, *schema.Verb, *schema.Config, *schema.Secret, *schema.Database: + case *schema.Data, *schema.Verb, *schema.Config, *schema.Secret, *schema.Database, *schema.FSM: } } } @@ -1494,34 +1494,38 @@ func (p *parseContext) getDeclForTypeName(name string) (enum schema.Decl, ok boo func (p *parseContext) markAsExported(node schema.Node) { _ = schema.Visit(node, func(n schema.Node, next func() error) error { - switch n := n.(type) { - case *schema.Enum: - n.Export = true - case *schema.TypeAlias: - n.Export = true - case *schema.Data: - n.Export = true - case *schema.Verb: - n.Export = true - case *schema.Ref: - if n.Module != "" && n.Module != p.module.Name { - break + if decl, ok := n.(schema.Decl); ok { + switch decl := decl.(type) { + case *schema.Enum: + decl.Export = true + case *schema.TypeAlias: + decl.Export = true + case *schema.Data: + decl.Export = true + case *schema.Verb: + decl.Export = true + case *schema.Config, *schema.Secret, *schema.Database, *schema.FSM: + return next() + } + } else if r, ok := n.(*schema.Ref); ok { + if r.Module != "" && r.Module != p.module.Name { + return next() } for _, d := range p.module.Decls { switch d := d.(type) { case *schema.Enum: - if d.Name != n.Name { + if d.Name != r.Name { continue } case *schema.TypeAlias: - if d.Name != n.Name { + if d.Name != r.Name { continue } case *schema.Data: - if d.Name != n.Name { + if d.Name != r.Name { continue } - case *schema.Verb, *schema.Config, *schema.Secret, *schema.Database: + case *schema.Verb, *schema.Config, *schema.Secret, *schema.Database, *schema.FSM: // does not support implicit exporting continue default: @@ -1533,7 +1537,6 @@ func (p *parseContext) markAsExported(node schema.Node) { } } } - case *schema.Config, *schema.Secret, *schema.Database, *schema.TypeParameter, *schema.EnumVariant: } return next() })