@@ -98,12 +98,20 @@ public override bool VisitArrayType(ArrayType array, TypeQualifiers quals)
98
98
else
99
99
{
100
100
var arrayType = array . Type . Desugar ( ) ;
101
+ var finalArrayType = arrayType . GetPointee ( ) ?? arrayType ;
101
102
Class @class ;
102
- if ( arrayType . TryGetClass ( out @class ) && @class . IsRefType )
103
- supportBefore . WriteLineIndent (
104
- "{0}[i] = {1}.{2}(*(({1}.{3}*)&({4}[i * sizeof({1}.{3})])));" ,
105
- value , array . Type , Helpers . CreateInstanceIdentifier ,
106
- Helpers . InternalStruct , Context . ReturnVarName ) ;
103
+ if ( ( finalArrayType . TryGetClass ( out @class ) ) && @class . IsRefType )
104
+ {
105
+ if ( arrayType == finalArrayType )
106
+ supportBefore . WriteLineIndent (
107
+ "{0}[i] = {1}.{2}(*(({1}.{3}*)&({4}[i * sizeof({1}.{3})])));" ,
108
+ value , array . Type , Helpers . CreateInstanceIdentifier ,
109
+ Helpers . InternalStruct , Context . ReturnVarName ) ;
110
+ else
111
+ supportBefore . WriteLineIndent (
112
+ $@ "{ value } [i] = { finalArrayType } .{ Helpers . CreateInstanceIdentifier } (({
113
+ CSharpTypePrinter . IntPtrType } ) { Context . ReturnVarName } [i]);" ) ;
114
+ }
107
115
else
108
116
{
109
117
if ( arrayType . IsPrimitiveType ( PrimitiveType . Char ) &&
@@ -483,7 +491,6 @@ public override bool VisitArrayType(ArrayType array, TypeQualifiers quals)
483
491
if ( ! VisitType ( array , quals ) )
484
492
return false ;
485
493
486
- var arrayType = array . Type . Desugar ( ) ;
487
494
switch ( array . SizeType )
488
495
{
489
496
case ArrayType . ArraySize . Constant :
@@ -497,18 +504,25 @@ public override bool VisitArrayType(ArrayType array, TypeQualifiers quals)
497
504
supportBefore . WriteLine ( "if ({0} != null)" , Context . ArgName ) ;
498
505
supportBefore . WriteStartBraceIndent ( ) ;
499
506
Class @class ;
500
- if ( arrayType . TryGetClass ( out @class ) && @class . IsRefType )
507
+ var arrayType = array . Type . Desugar ( ) ;
508
+ var finalArrayType = arrayType . GetPointee ( ) ?? arrayType ;
509
+ if ( finalArrayType . TryGetClass ( out @class ) && @class . IsRefType )
501
510
{
502
511
supportBefore . WriteLine ( "if (value.Length != {0})" , array . Size ) ;
503
512
ThrowArgumentOutOfRangeException ( ) ;
504
513
}
505
514
supportBefore . WriteLine ( "for (int i = 0; i < {0}; i++)" , array . Size ) ;
506
515
if ( @class != null && @class . IsRefType )
507
516
{
508
- supportBefore . WriteLineIndent (
509
- "*({1}.{2}*) &{0}[i * sizeof({1}.{2})] = *({1}.{2}*){3}[i].{4};" ,
510
- Context . ReturnVarName , arrayType , Helpers . InternalStruct ,
511
- Context . ArgName , Helpers . InstanceIdentifier ) ;
517
+ if ( finalArrayType == arrayType )
518
+ supportBefore . WriteLineIndent (
519
+ "*({1}.{2}*) &{0}[i * sizeof({1}.{2})] = *({1}.{2}*){3}[i].{4};" ,
520
+ Context . ReturnVarName , arrayType , Helpers . InternalStruct ,
521
+ Context . ArgName , Helpers . InstanceIdentifier ) ;
522
+ else
523
+ supportBefore . WriteLineIndent ( $@ "{ Context . ReturnVarName } [i] = ({
524
+ ( Context . Context . TargetInfo . PointerWidth == 64 ? "long" : "int" ) } ) {
525
+ Context . ArgName } [i].{ Helpers . InstanceIdentifier } ;" ) ;
512
526
}
513
527
else
514
528
{
0 commit comments