title: How to prevent method group from discarding nullability of generic reference type?
body: <p>Consider this generic identity function:</p>
  <pre class="lang-cs prettyprint-override"><code>T Id&lt;T&gt;(T x) =&gt; x;
  </code></pre>
  <p>If I use it in a lambda mapping the elements in an array of <code>string?</code> values, it works as expected (i.e. it preserves the information, that the values are nullable).</p>
  <pre class="lang-cs prettyprint-override"><code>var xs = new[] { (string?)&quot;foo&quot; };
  
  var ys = xs.Select(x =&gt; Id(x)); // inferred type of `ys` is IEnumerable&lt;string?&gt;
  string y = ys.Single();         // warning CS8600: Converting [...] possible null value to non-nullable type.
  </code></pre>
  <p>However, if I use it as a method group that information will be discarded.</p>
  <pre class="lang-cs prettyprint-override"><code>var xs = new[] { (string?)&quot;foo&quot; };
  
  var ys = xs.Select(Id); // inferred type of `ys` is IEnumerable&lt;string&gt;
  string y = ys.Single(); // no warning CS8600
  </code></pre>
  <p>What's going on here? Is this a compiler bug or a known limitation of nullable reference types?</p>
  <p>As a workaround I could declare <code>Id</code> like below to get the expected warning in the second example:</p>
  <pre class="lang-cs prettyprint-override"><code>T? Id&lt;T&gt;(T? x) =&gt; x;
  </code></pre>
  <p>But this seems overly expressive to me.</p>
  <p>I'm using C# 10.0.</p>
  <p>Working example: <a href="https://dotnetfiddle.net/SEHIb6" rel="nofollow noreferrer">https://dotnetfiddle.net/SEHIb6</a></p>