File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed
ICSharpCode.Decompiler.Tests/TestCases/Pretty
ICSharpCode.Decompiler/CSharp Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -316,5 +316,15 @@ private static dynamic DynamicNullProp(dynamic a)
316316 {
317317 return a ? . b . c ( 1 ) ? . d [ 10 ] ;
318318 }
319+
320+ private static string Issue3181 ( )
321+ {
322+ #if EXPECTED_OUTPUT
323+ return ( ( int ? ) null ) ? . ToString ( ) ;
324+ #else
325+ int ? x = null ;
326+ return x ? . ToString ( ) ;
327+ #endif
328+ }
319329 }
320330}
Original file line number Diff line number Diff line change @@ -626,19 +626,29 @@ internal ExpressionWithResolveResult GetDefaultValueExpression(IType type)
626626 Expression expr ;
627627 IType constantType ;
628628 object constantValue ;
629- if ( type . IsReferenceType == true || type . IsKnownType ( KnownTypeCode . NullableOfT ) )
629+ if ( type . IsReferenceType == true )
630630 {
631631 expr = new NullReferenceExpression ( ) ;
632632 constantType = SpecialType . NullType ;
633633 constantValue = null ;
634+ return expr . WithRR ( new ConstantResolveResult ( constantType , constantValue ) ) ;
635+ }
636+ else if ( type . IsKnownType ( KnownTypeCode . NullableOfT ) )
637+ {
638+ expr = new NullReferenceExpression ( ) ;
639+ constantType = SpecialType . NullType ;
640+ constantValue = null ;
641+ var crr = new ConstantResolveResult ( constantType , constantValue ) ;
642+ return new CastExpression ( ConvertType ( type ) , expr . WithRR ( crr ) )
643+ . WithRR ( new ConversionResolveResult ( type , crr , Conversion . NullLiteralConversion ) ) ;
634644 }
635645 else
636646 {
637647 expr = new DefaultValueExpression ( ConvertType ( type ) ) ;
638648 constantType = type ;
639649 constantValue = CSharpResolver . GetDefaultValue ( type ) ;
650+ return expr . WithRR ( new ConstantResolveResult ( constantType , constantValue ) ) ;
640651 }
641- return expr . WithRR ( new ConstantResolveResult ( constantType , constantValue ) ) ;
642652 }
643653
644654 protected internal override TranslatedExpression VisitSizeOf ( SizeOf inst , TranslationContext context )
You can’t perform that action at this time.
0 commit comments