Skip to content

Commit f5ecf68

Browse files
authored
Merge pull request #144 from 8chan-co/patch-1
sizeof improvements xp
2 parents 24b53d6 + fa46961 commit f5ecf68

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

Packages/com.merlin.UdonSharp/Editor/Compiler/Binder/BinderSyntaxVisitor.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -351,12 +351,16 @@ public override BoundNode VisitTypeOfExpression(TypeOfExpressionSyntax node)
351351
public override BoundNode VisitSizeOfExpression(SizeOfExpressionSyntax node)
352352
{
353353
Type type = GetTypeSymbol(node.Type).UdonType.SystemType;
354-
355-
int size = Marshal.SizeOf(type);
356-
357-
if (type == typeof(bool))
358-
size = 1; // C# sizeof(bool) is 1 byte but Marshal.SizeOf is 4 bytes for bool :(
359-
354+
355+
if (type.IsEnum) // this adds support for enumerated types > ~ <
356+
{
357+
type = type.GetEnumUnderlyingType();
358+
}
359+
360+
// C# sizeof(bool) is 1 byte but Marshal.SizeOf is 4 bytes for bool :(
361+
// assume boolean at first, otherwise; let the marshaller report the size :D
362+
int size = type == typeof(bool) ? sizeof(bool) : Marshal.SizeOf(type);
363+
360364
return new BoundConstantExpression(size, Context.GetTypeSymbol(SpecialType.System_Int32));
361365
}
362366

0 commit comments

Comments
 (0)