Templates are working, but the code is ugly af
This commit is contained in:
@@ -406,7 +406,7 @@ public sealed class Binder
|
||||
|
||||
if (boundExpression.Type is NubCustomType customType)
|
||||
{
|
||||
var traits = _definitionTable.LookupTrait(customType.Namespace, customType.Name).ToArray();
|
||||
var traits = _definitionTable.LookupTrait(customType).ToArray();
|
||||
if (traits.Length > 0)
|
||||
{
|
||||
if (traits.Length > 1)
|
||||
@@ -433,7 +433,7 @@ public sealed class Binder
|
||||
}
|
||||
}
|
||||
|
||||
var structs = _definitionTable.LookupStruct(customType.Namespace, customType.Name).ToArray();
|
||||
var structs = _definitionTable.LookupStruct(customType).ToArray();
|
||||
if (structs.Length > 0)
|
||||
{
|
||||
if (structs.Length > 1)
|
||||
@@ -463,12 +463,14 @@ public sealed class Binder
|
||||
|
||||
private BoundStructInitializer BindStructInitializer(StructInitializerSyntax expression)
|
||||
{
|
||||
if (expression.StructType is not CustomTypeSyntax structType)
|
||||
var boundType = BindType(expression.StructType);
|
||||
|
||||
if (boundType is not NubCustomType structType)
|
||||
{
|
||||
throw new BindException(Diagnostic.Error($"Cannot initialize non-struct type {expression.StructType}").Build());
|
||||
}
|
||||
|
||||
var structs = _definitionTable.LookupStruct(structType.Namespace, structType.Name).ToArray();
|
||||
var structs = _definitionTable.LookupStruct(structType).ToArray();
|
||||
|
||||
if (structs.Length == 0)
|
||||
{
|
||||
@@ -501,7 +503,7 @@ public sealed class Binder
|
||||
initializers[field] = BindExpression(initializer, BindType(fields[0].Type));
|
||||
}
|
||||
|
||||
return new BoundStructInitializer(expression.Tokens, (NubCustomType)BindType(structType), initializers);
|
||||
return new BoundStructInitializer(expression.Tokens, structType, initializers);
|
||||
}
|
||||
|
||||
private BoundUnaryExpression BindUnaryExpression(UnaryExpressionSyntax expression)
|
||||
@@ -636,7 +638,7 @@ public sealed class Binder
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
}),
|
||||
StringTypeSyntax => new NubStringType(),
|
||||
TemplateTypeSyntax templateTypeSyntax => throw new NotImplementedException(),
|
||||
TemplatedCustomTypeSyntax type => new NubCustomType(type.Namespace, type.MangledName()),
|
||||
VoidTypeSyntax => new NubVoidType(),
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(node))
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user