Skip to content

Commit 102ddca

Browse files
committed
#2050: Add additional test where the integer field is nested in a struct field.
1 parent 00b6545 commit 102ddca

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

ICSharpCode.Decompiler.Tests/TestCases/Correctness/NullableTests.cs

+27
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,15 @@ static void Main()
2727
AvoidLifting();
2828
BitNot();
2929
FieldAccessOrderOfEvaluation(null);
30+
FieldAccessOrderOfEvaluationWithStruct(null);
3031
ArrayAccessOrderOfEvaluation();
3132
}
3233

34+
struct SomeStruct
35+
{
36+
public int IntField;
37+
}
38+
3339
static void AvoidLifting()
3440
{
3541
Console.WriteLine("MayThrow:");
@@ -113,6 +119,27 @@ static void FieldAccessOrderOfEvaluation(NullableTests c)
113119
}
114120
}
115121

122+
SomeStruct structField;
123+
124+
static void FieldAccessOrderOfEvaluationWithStruct(NullableTests c)
125+
{
126+
Console.WriteLine("GetInt, then NRE (with struct):");
127+
try {
128+
c.structField.IntField = GetValue<int>();
129+
} catch (Exception ex) {
130+
Console.WriteLine(ex.Message);
131+
}
132+
Console.WriteLine("NRE before GetInt (with struct):");
133+
try {
134+
#if CS60
135+
ref SomeStruct s = ref c.structField;
136+
s.IntField = GetValue<int>();
137+
#endif
138+
} catch (Exception ex) {
139+
Console.WriteLine(ex.Message);
140+
}
141+
}
142+
116143
static T[] GetArray<T>()
117144
{
118145
Console.WriteLine("GetArray");

0 commit comments

Comments
 (0)