-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Closed
Labels
Area-CompilersBugFeature - Nullable Reference TypesNullable Reference TypesNullable Reference Typeshelp wantedThe issue is "up for grabs" - add a comment if you are interested in working on itThe issue is "up for grabs" - add a comment if you are interested in working on it
Milestone
Description
Version Used:
VisualStudio.16.Release/16.8.4+30907.101
C# Tools 3.8.0-5.20604.10+9ed4b774d20940880de8df1ca8b07508aa01c8cd
Steps to Reproduce:
<LangVersion>9</LangVersion>
using System.Diagnostics.CodeAnalysis;
#nullable enable
interface IOperation<T> { }
class StringOperation : IOperation<string?> { }
class C {
void M() {
TestA(new StringOperation(), out string? discard1); // 1: no warning
TestA(new StringOperation(), out string? _); // 2: CS8620
TestA(new StringOperation(), out _); // 3: CS8620
TestB(new StringOperation(), out string? discard2); // 4: CS8620
TestB(new StringOperation(), out string? _); // 5: CS8620
TestB(new StringOperation(), out _); // 6: CS8620
}
void TestA<T>(IOperation<T> operation, [MaybeNull] out T result) => result = default;
void TestB<T>(IOperation<T> operation, out T? result) => result = default;
}
Expected Behavior:
- Ideally, no warnings at all, I would expect the compiler to see that
T?
/[MaybeNull] T
can be matched bystring?
(in effect making itstring??
) without warnings. CurrentlyT
is always inferred to bestring
instead ofstring?
, resulting in warnings. - At the very least, 1 and 2 should have same behavior: the specified types are the same, only the parameter name is missing in 2.
Actual Behavior:
Warnings everywhere but on 1.
Metadata
Metadata
Assignees
Labels
Area-CompilersBugFeature - Nullable Reference TypesNullable Reference TypesNullable Reference Typeshelp wantedThe issue is "up for grabs" - add a comment if you are interested in working on itThe issue is "up for grabs" - add a comment if you are interested in working on it