From 71691784e76d0c87dacf10846db4f077c9210c49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Eriksson?= Date: Sat, 8 Jun 2024 17:35:23 +0200 Subject: [PATCH] parser/encoding: handle unions --- parser/encoding/rpc.go | 19 +++++++++++++++++++ tsparser/src/parser/types/type_resolve.rs | 6 +++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/parser/encoding/rpc.go b/parser/encoding/rpc.go index 6bb6ce82640..678d65d1ce4 100644 --- a/parser/encoding/rpc.go +++ b/parser/encoding/rpc.go @@ -379,6 +379,25 @@ func GetConcreteType(appDecls []*schema.Decl, originalType *schema.Type, typeArg return resolveTypeParams(&schema.Type{Typ: &schema.Type_Map{Map: mapType}}, typeArgs), nil + case *schema.Type_Union: + // If there are no type arguments, we've got a concrete type + if len(typeArgs) == 0 { + return originalType, nil + } + + types := make([]*schema.Type, len(typ.Union.Types)) + for i, t := range typ.Union.Types { + // Deep copy the type + cloned := proto.Clone(t).(*schema.Type) + types[i] = resolveTypeParams(cloned, typeArgs) + } + + return &schema.Type{Typ: &schema.Type_Union{ + Union: &schema.Union{ + Types: types, + }, + }}, nil + case *schema.Type_List: // If there are no type arguments, we've got a concrete type if len(typeArgs) == 0 { diff --git a/tsparser/src/parser/types/type_resolve.rs b/tsparser/src/parser/types/type_resolve.rs index 32bf5185834..2513b771b8a 100644 --- a/tsparser/src/parser/types/type_resolve.rs +++ b/tsparser/src/parser/types/type_resolve.rs @@ -758,9 +758,9 @@ impl<'a> Ctx<'a> { other => other, }, - ast::UnaryOp::Bang - | ast::UnaryOp::Tilde - | ast::UnaryOp::Delete => self.expr(&expr.arg), + ast::UnaryOp::Bang | ast::UnaryOp::Tilde | ast::UnaryOp::Delete => { + self.expr(&expr.arg) + } }, ast::Expr::Update(expr) => self.expr(&expr.arg), ast::Expr::Bin(expr) => {