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);
}
--- /dev/null
+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");
+ }
+}
</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>
<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">
</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">