title: Difference in nullability of reference types error when building with .NET 5 SDK
body: <p>I have implemented the following extension methods on <code>IDictionary</code>, which will try to get a value from a dictionary, but return a default value (either <code>default(T)</code> or user-provided) if the key doesn't exist. The first method without a user-provided value will call through to the other method with <code>default</code>.</p>
  <pre class="lang-cs prettyprint-override"><code>[return: MaybeNull]
  public static T GetValueOrDefault&lt;TKey, T&gt;(this IDictionary&lt;TKey, T&gt; source, TKey key) where TKey : notnull
  {
      return GetValueOrDefault(source, key, defaultValue: default);
  }
  
  [return: MaybeNull]
  public static T GetValueOrDefault&lt;TKey, T&gt;(this IDictionary&lt;TKey, T&gt; source, TKey key, [AllowNull] T defaultValue) where TKey : notnull
  {
      if (source is null) throw new ArgumentNullException(nameof(source));
      if (key is null) throw new ArgumentNullException(nameof(key));
      
      if (source.TryGetValue(key, out var item))
      {
          return item;
      }
  
      return defaultValue;
  }
  </code></pre>
  <p>With .NET SDK 3.1.100 this code builds fine. However, with the newest .NET SDK 5.0.101, I get the following error message:</p>
  <blockquote>
  <p>error CS8620: Argument of type 'IDictionary&lt;TKey, T&gt;' cannot be used for parameter 'source' of type 'IDictionary&lt;TKey, T?&gt;' in 'T? DictionaryExtensions.GetValueOrDefault&lt;TKey, T?&gt;(IDictionary&lt;TKey, T?&gt; source, TKey key, T? defaultValue)' due to differences in the nullability of reference types.</p>
  </blockquote>
  <p>It complains about the use of <code>default</code> in <code>GetValueOrDefault(source, key, defaultValue: default)</code>. Using <code>default!</code> suppresses the error message of course, but the value is supposed to be nullable (hence the <code>AllowNullAttribute</code> on <code>defaultValue</code>). Or maybe it is deducing that <code>T</code> is nullable due to the attribute and usage, and won't allow a call with the non-nullable <code>T</code>?</p>
  <p>The error is only produced when <code>T</code> is generic and not constrained to <code>class</code>. For instance, the following code does not produce the error:</p>
  <pre><code>var dict = new Dictionary&lt;string, string&gt;();
  dict.GetValueOrDefault(&quot;key&quot;, null);
  </code></pre>
  <p>Am I doing something wrong? Has the constraints on nullable reference types been further tightened with the new .NET version? Is this simply a bug with .NET SDK 5.0.101?</p>