Skip to content

Commit

Permalink
Few more improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
RReverser committed Dec 17, 2024
1 parent cae94ca commit 189251a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 44 deletions.
9 changes: 8 additions & 1 deletion crates/bindings-csharp/BSATN.Codegen/Type.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@ public MemberDeclaration(ISymbol member, ITypeSymbol type, DiagReporter diag)
{
TypeInfo = GetTypeInfo(type);
}
catch (UnresolvedTypeException)
{
// If it's an unresolved type, this error will have been already highlighted by .NET itself, no need to add noise.
// Just add some dummy type to avoid further errors.
// Note that we just use `object` here because emitting the unresolved type's name again would produce more of said noise.
TypeInfo = "SpacetimeDB.BSATN.Unsupported<object>";
}
catch (Exception e)
{
diag.Report(ErrorDescriptor.UnsupportedType, (member, type, e));
// dummy type; can't instantiate an interface, but at least it will produce fewer noisy errors
// dummy BSATN implementation to produce fewer noisy errors
TypeInfo = $"SpacetimeDB.BSATN.Unsupported<{Type}>";
}
}
Expand Down
5 changes: 4 additions & 1 deletion crates/bindings-csharp/BSATN.Codegen/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ IncrementalGeneratorInitializationContext context

public static string MakeRwTypeParam(string typeParam) => typeParam + "RW";

public class UnresolvedTypeException(INamedTypeSymbol type)
: InvalidOperationException($"Could not resolve type {type}") { }

public static string GetTypeInfo(ITypeSymbol type)
{
// We need to distinguish handle nullable reference types specially:
Expand Down Expand Up @@ -120,7 +123,7 @@ static string GetTypeInfoForNamedType(INamedTypeSymbol type)
{
if (type.TypeKind == Microsoft.CodeAnalysis.TypeKind.Error)
{
throw new InvalidOperationException($"Could not resolve type {type}");
throw new UnresolvedTypeException(type);
}
if (type.TypeKind == Microsoft.CodeAnalysis.TypeKind.Enum)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,5 @@
NotConfigurable
]
}
},
{/*
internal static readonly SpacetimeDB.BSATN.Unsupported<System.Exception> UnsupportedSystemType = new();
internal static readonly SpacetimeDB.BSATN.Unsupported<UnresolvedType> UnresolvedType = new();
^^^^^^^^^^^^^^
internal static readonly SpacetimeDB.BSATN.Unsupported<LocalEnum> UnsupportedEnum = new();
*/
Message: The type or namespace name 'UnresolvedType' could not be found (are you missing a using directive or an assembly reference?),
Severity: Error,
Descriptor: {
Id: CS0246,
Title: ,
HelpLink: https://msdn.microsoft.com/query/roslyn.query?appId=roslyn&k=k(CS0246),
MessageFormat: The type or namespace name '{0}' could not be found (are you missing a using directive or an assembly reference?),
Category: Compiler,
DefaultSeverity: Error,
IsEnabledByDefault: true,
CustomTags: [
Compiler,
Telemetry,
NotConfigurable
]
}
}
]

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

Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,6 @@
}
},
{/*
public Exception UnsupportedSystemType;
public UnresolvedType UnresolvedType;
^^^^^^^^^^^^^^
public LocalEnum UnsupportedEnum;
*/
Message: BSATN implementation for UnresolvedType is not found: Could not resolve type UnresolvedType,
Severity: Error,
Descriptor: {
Id: BSATN0001,
Title: Unsupported type,
MessageFormat: BSATN implementation for {0} is not found: {1},
Category: SpacetimeDB.BSATN,
DefaultSeverity: Error,
IsEnabledByDefault: true
}
},
{/*
public UnresolvedType UnresolvedType;
public LocalEnum UnsupportedEnum;
^^^^^^^^^^^^^^^
Expand Down

0 comments on commit 189251a

Please sign in to comment.