@@ -1571,7 +1571,9 @@ impl<'a, 'ast> Generator<'a, 'ast> {
15711571 } ;
15721572 self . emit_function_start_mark ( & ctx) ;
15731573 let value = match written {
1574- InitializerValue :: Expression ( value) => self . lower_expression ( & mut ctx, value) ,
1574+ // converted to the field's type: `float value = 0;` stores a
1575+ // Single, not the Int32 the literal is
1576+ InitializerValue :: Expression ( value) => self . owned_value_as ( & mut ctx, value, & ty) ,
15751577 // `static int[] Steps = { 1, 2 };`
15761578 InitializerValue :: Nested ( nested) => {
15771579 self . lower_array_shorthand ( & mut ctx, & ty, nested, nested. span ( ) )
@@ -4014,6 +4016,30 @@ fn literal_heap_init(expression: &Expression, udon_type: &str) -> Option<HeapIni
40144016 let value = if negated { -value } else { value } ;
40154017 i32:: try_from ( value) . ok ( ) . map ( HeapInit :: Int32 )
40164018 }
4019+ // an integer literal converts implicitly to the wider types: the
4020+ // default is then of the slot's type, as `float value = 0;` means
4021+ ( LiteralExpression :: Integer ( text) , "SystemInt64" ) => {
4022+ let raw: String = text. value . chars ( ) . filter ( |c| * c != '_' ) . collect ( ) ;
4023+ let value = raw. parse :: < i64 > ( ) . ok ( ) ?;
4024+ Some ( HeapInit :: Int64 ( if negated { -value } else { value } ) )
4025+ }
4026+ ( LiteralExpression :: Integer ( text) , "SystemUInt32" ) if !negated => {
4027+ let raw: String = text. value . chars ( ) . filter ( |c| * c != '_' ) . collect ( ) ;
4028+ raw. parse :: < u32 > ( ) . ok ( ) . map ( HeapInit :: UInt32 )
4029+ }
4030+ ( LiteralExpression :: Integer ( text) , "SystemSingle" ) => {
4031+ let raw: String = text. value . chars ( ) . filter ( |c| * c != '_' ) . collect ( ) ;
4032+ let value = raw. parse :: < i64 > ( ) . ok ( ) ?;
4033+ let value = if negated { -value } else { value } ;
4034+ // exactly representable, as C# folds it
4035+ ( value. unsigned_abs ( ) <= 1 << 24 ) . then_some ( HeapInit :: Single ( value as f32 ) )
4036+ }
4037+ ( LiteralExpression :: Integer ( text) , "SystemDouble" ) => {
4038+ let raw: String = text. value . chars ( ) . filter ( |c| * c != '_' ) . collect ( ) ;
4039+ let value = raw. parse :: < i64 > ( ) . ok ( ) ?;
4040+ let value = if negated { -value } else { value } ;
4041+ ( value. unsigned_abs ( ) <= 1 << 53 ) . then_some ( HeapInit :: Double ( value as f64 ) )
4042+ }
40174043 ( LiteralExpression :: Real ( text) , "SystemSingle" ) => {
40184044 let raw: String = text. value . chars ( ) . filter ( |c| * c != '_' ) . collect ( ) ;
40194045 let value = raw. strip_suffix ( [ 'f' , 'F' ] ) ?. parse :: < f32 > ( ) . ok ( ) ?;
0 commit comments