@ -27,6 +27,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
@@ -27,6 +27,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
AvoidLifting ( ) ;
BitNot ( ) ;
FieldAccessOrderOfEvaluation ( null ) ;
ArrayAccessOrderOfEvaluation ( ) ;
}
static void AvoidLifting ( )
@ -85,10 +86,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
@@ -85,10 +86,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
}
static int GetInt ( )
static T GetValue < T > ( )
{
Console . WriteLine ( "got int " ) ;
return 4 2 ;
Console . WriteLine ( "GetValue " ) ;
return default ( T ) ;
}
int intField ;
@ -97,7 +98,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
@@ -97,7 +98,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
{
Console . WriteLine ( "GetInt, then NRE:" ) ;
try {
c . intField = GetInt ( ) ;
c . intField = GetValue < int > ( ) ;
} catch ( Exception ex ) {
Console . WriteLine ( ex . Message ) ;
}
@ -105,11 +106,51 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
@@ -105,11 +106,51 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
try {
#if CS60
ref int i = ref c . intField ;
i = GetInt ( ) ;
i = GetValue < int > ( ) ;
#endif
} catch ( Exception ex ) {
Console . WriteLine ( ex . Message ) ;
}
}
static T [ ] GetArray < T > ( )
{
Console . WriteLine ( "GetArray" ) ;
return null ;
}
static int GetIndex ( )
{
Console . WriteLine ( "GetIndex" ) ;
return 0 ;
}
static void ArrayAccessOrderOfEvaluation ( )
{
Console . WriteLine ( "GetArray direct:" ) ;
try {
GetArray < int > ( ) [ GetIndex ( ) ] = GetValue < int > ( ) ;
} catch ( Exception ex ) {
Console . WriteLine ( ex . Message ) ;
}
Console . WriteLine ( "GetArray with ref:" ) ;
try {
#if CS60
ref int elem = ref GetArray < int > ( ) [ GetIndex ( ) ] ;
elem = GetValue < int > ( ) ;
#endif
} catch ( Exception ex ) {
Console . WriteLine ( ex . Message ) ;
}
Console . WriteLine ( "GetArray direct with value-type:" ) ;
try {
// This line is mis-compiled by legacy csc:
// with the legacy compiler the NRE is thrown before the GetValue call;
// with Roslyn the NRE is thrown after the GetValue call.
GetArray < TimeSpan > ( ) [ GetIndex ( ) ] = GetValue < TimeSpan > ( ) ;
} catch ( Exception ex ) {
Console . WriteLine ( ex . Message ) ;
}
}
}
}