From 102ddcadc77f655beed616f672e8641a1fadf05a Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sun, 16 Aug 2020 16:49:44 +0200 Subject: [PATCH] #2050: Add additional test where the integer field is nested in a struct field. --- .../TestCases/Correctness/NullableTests.cs | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Correctness/NullableTests.cs b/ICSharpCode.Decompiler.Tests/TestCases/Correctness/NullableTests.cs index ab73363ac..9200488bf 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Correctness/NullableTests.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Correctness/NullableTests.cs @@ -27,9 +27,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness AvoidLifting(); BitNot(); FieldAccessOrderOfEvaluation(null); + FieldAccessOrderOfEvaluationWithStruct(null); ArrayAccessOrderOfEvaluation(); } + struct SomeStruct + { + public int IntField; + } + static void AvoidLifting() { Console.WriteLine("MayThrow:"); @@ -113,6 +119,27 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness } } + SomeStruct structField; + + static void FieldAccessOrderOfEvaluationWithStruct(NullableTests c) + { + Console.WriteLine("GetInt, then NRE (with struct):"); + try { + c.structField.IntField = GetValue(); + } catch (Exception ex) { + Console.WriteLine(ex.Message); + } + Console.WriteLine("NRE before GetInt (with struct):"); + try { +#if CS60 + ref SomeStruct s = ref c.structField; + s.IntField = GetValue(); +#endif + } catch (Exception ex) { + Console.WriteLine(ex.Message); + } + } + static T[] GetArray() { Console.WriteLine("GetArray");