File tree Expand file tree Collapse file tree
Packages/com.merlin.UdonSharp/Editor/Compiler/Binder Expand file tree Collapse file tree Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments