diff options
author | Marek Safar <marek.safar@gmail.com> | 2015-09-08 11:54:29 +0300 |
---|---|---|
committer | Marek Safar <marek.safar@gmail.com> | 2015-09-08 11:59:52 +0300 |
commit | 6294c96bab94507577b483ab7bd48f624456a284 (patch) | |
tree | 4c301d970316739984ef260714218572d28520e8 /mcs | |
parent | 86c5ca89ac8f19726f46cac77c4f2f22c4078eaa (diff) |
[mcs] Null operator on value type extension argument. Fixes #33754
Diffstat (limited to 'mcs')
-rw-r--r-- | mcs/mcs/codegen.cs | 10 | ||||
-rw-r--r-- | mcs/tests/test-null-operator-18.cs | 20 | ||||
-rw-r--r-- | mcs/tests/ver-il-net_4_x.xml | 37 |
3 files changed, 50 insertions, 17 deletions
diff --git a/mcs/mcs/codegen.cs b/mcs/mcs/codegen.cs index d86bf2c3d1e..c224b0d636a 100644 --- a/mcs/mcs/codegen.cs +++ b/mcs/mcs/codegen.cs @@ -1260,10 +1260,12 @@ namespace Mono.CSharp instance_address.AddressOf (ec, AddressOp.Load); } else if (unwrap != null) { unwrap.Emit (ec); - var tmp = ec.GetTemporaryLocal (unwrap.Type); - ec.Emit (OpCodes.Stloc, tmp); - ec.Emit (OpCodes.Ldloca, tmp); - ec.FreeTemporaryLocal (tmp, unwrap.Type); + if (addressRequired) { + var tmp = ec.GetTemporaryLocal (unwrap.Type); + ec.Emit (OpCodes.Stloc, tmp); + ec.Emit (OpCodes.Ldloca, tmp); + ec.FreeTemporaryLocal (tmp, unwrap.Type); + } } else if (!conditional_access_dup) { instance.Emit (ec); } diff --git a/mcs/tests/test-null-operator-18.cs b/mcs/tests/test-null-operator-18.cs new file mode 100644 index 00000000000..ad0d72e9b73 --- /dev/null +++ b/mcs/tests/test-null-operator-18.cs @@ -0,0 +1,20 @@ +using System; + +static class MainClass +{ + public static void Main() + { + TestBug(); + } + + public static void TestBug() + { + int? value = null; + value?.Test(); + } + + public static void Test(this int value) + { + Console.WriteLine("Not null"); + } +} diff --git a/mcs/tests/ver-il-net_4_x.xml b/mcs/tests/ver-il-net_4_x.xml index 2f2884795e5..cda463fd51f 100644 --- a/mcs/tests/ver-il-net_4_x.xml +++ b/mcs/tests/ver-il-net_4_x.xml @@ -69125,6 +69125,11 @@ </type> </test> <test name="test-null-operator-08.cs"> + <type name="S"> + <method name="Void Foo(Boolean)" attrs="486"> + <size>38</size> + </method> + </type> <type name="Program"> <method name="Void M[T](T)" attrs="145"> <size>88</size> @@ -69138,25 +69143,18 @@ <method name="Void M3[T](System.Nullable`1[T])" attrs="145"> <size>106</size> </method> - <method name="Void Main()" attrs="145"> - <size>165</size> - </method> - <method name="Void .ctor()" attrs="6278"> - <size>7</size> - </method> - </type> - <type name="S"> - <method name="Void Foo(Boolean)" attrs="486"> - <size>38</size> - </method> - </type> - <type name="Program"> <method name="Void TestAddress_1[T](T)" attrs="145"> <size>56</size> </method> <method name="Void TestAddress_2[T](T[])" attrs="145"> <size>82</size> </method> + <method name="Void Main()" attrs="145"> + <size>165</size> + </method> + <method name="Void .ctor()" attrs="6278"> + <size>7</size> + </method> </type> </test> <test name="test-null-operator-09.cs"> @@ -69377,6 +69375,19 @@ </method> </type> </test> + <test name="test-null-operator-18.cs"> + <type name="MainClass"> + <method name="Void Main()" attrs="150"> + <size>7</size> + </method> + <method name="Void TestBug()" attrs="150"> + <size>38</size> + </method> + <method name="Void Test(Int32)" attrs="150"> + <size>12</size> + </method> + </type> + </test> <test name="test-partial-01.cs"> <type name="Foo.Hello"> <method name="Void .ctor()" attrs="6278"> |