@@ -84,6 +84,12 @@ public static TypeUse Parse(ISymbol member, ITypeSymbol typeSymbol, DiagReporter
8484 ) ,
8585 INamedTypeSymbol named => named . OriginalDefinition . ToString ( ) switch
8686 {
87+ "SpacetimeDB.Result<T, E>" or "SpacetimeDB.Result<T,E>" => new ResultUse (
88+ type ,
89+ typeInfo ,
90+ Parse ( member , named . TypeArguments [ 0 ] , diag ) ,
91+ Parse ( member , named . TypeArguments [ 1 ] , diag )
92+ ) ,
8793 "System.Collections.Generic.List<T>" => new ListUse (
8894 type ,
8995 typeInfo ,
@@ -101,6 +107,14 @@ public static TypeUse Parse(ISymbol member, ITypeSymbol typeSymbol, DiagReporter
101107 } ;
102108 }
103109
110+ /// <summary>
111+ /// Get the name of the BSATN struct for this type.
112+ /// </summary>
113+ public virtual string to_bsatn_string ( )
114+ {
115+ return this . BSATNName ;
116+ }
117+
104118 /// <summary>
105119 /// Get a statement that declares outVar and assigns (inVar1 logically-equals inVar2) to it.
106120 /// logically-equals:
@@ -133,6 +147,40 @@ public abstract string EqualsStatement(
133147 public abstract string GetHashCodeStatement ( string inVar , string outVar , int level = 0 ) ;
134148}
135149
150+ /// <summary>
151+ /// A use of a Result<T, E> type.
152+ /// </summary>
153+ public sealed record ResultUse : TypeUse
154+ {
155+ public TypeUse Ok { get ; }
156+ public TypeUse Err { get ; }
157+
158+ public string TypeName { get ; }
159+
160+ public ResultUse ( string typeName , string typeInfo , TypeUse ok , TypeUse err )
161+ : base ( typeName , typeInfo )
162+ {
163+ Ok = ok ;
164+ Err = err ;
165+ TypeName = typeName ;
166+ }
167+
168+ public override string to_bsatn_string ( )
169+ {
170+ return $ "{ TypeName } .BSATN<{ Ok . BSATNName } , { Err . BSATNName } >";
171+ }
172+
173+ public override string EqualsStatement (
174+ string inVar1 ,
175+ string inVar2 ,
176+ string outVar ,
177+ int level = 0
178+ ) => $ "var { outVar } = { inVar1 } == { inVar2 } ;";
179+
180+ public override string GetHashCodeStatement ( string inVar , string outVar , int level = 0 ) =>
181+ $ "var { outVar } = { inVar } .GetHashCode();";
182+ }
183+
136184/// <summary>
137185/// A use of an enum type.
138186/// (This is a C# enum, not one of our tagged enums.)
@@ -348,7 +396,7 @@ IEnumerable<MemberDeclaration> members
348396 return string . Join (
349397 "\n " ,
350398 members . Select ( m =>
351- $ "{ visStr } static readonly { m . Type . BSATNName } { m . Name } { TypeUse . BsatnFieldSuffix } = new();"
399+ $ "{ visStr } static readonly { m . Type . to_bsatn_string ( ) } { m . Name } { TypeUse . BsatnFieldSuffix } = new();"
352400 )
353401 ) ;
354402 }
0 commit comments