Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix ignoring [MaybeNull] during type inference #66190

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3155,7 +3155,10 @@ private static EffectiveParameters GetEffectiveParametersInNormalForm<TMember>(
continue;
}
var parameter = parameters[parm];
types.Add(parameter.TypeWithAnnotations);
types.Add((parameter.GetFlowAnalysisAnnotations() == FlowAnalysisAnnotations.MaybeNull)
? parameter.TypeWithAnnotations.AsAnnotated()
: parameter.TypeWithAnnotations
);

RefKind argRefKind = hasAnyRefArg ? argumentRefKinds[arg] : RefKind.None;
RefKind paramRefKind = GetEffectiveParameterRefKind(parameter, argRefKind, isMethodGroupConversion, allowRefOmittedArguments, binder, ref hasAnyRefOmittedArgument);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,30 @@ static void Goo<T>(ref T[] x)
Diagnostic(ErrorCode.ERR_CantInferMethTypeArgs, "Goo").WithArguments("C.Goo<T>(ref T[])"));
}

[Fact]
public void Bug50782()
{
string source = @"
using System.Diagnostics.CodeAnalysis;
#nullable enable
interface IOperation<T> { }
class StringOperation : IOperation<string?> { }
class C {
void M() {
TestA(new StringOperation(), out string? discard1);

TestB(new StringOperation(), out string? discard2);
}
void TestA<T>(IOperation<T> operation, [MaybeNull] out T result) => result = default;
void TestB<T>(IOperation<T> operation, out T? result) => result = default;
}
";
CreateCompilation(source, targetFramework: TargetFramework.Net70).VerifyDiagnostics(
Diagnostic(ErrorCode.WRN_NullabilityMismatchInArgument, "new StringOperation()").WithArguments("StringOperation", "IOperation<string>", "operation", "void C.TestA<string>(IOperation<string> operation, out string result)").WithLocation(8, 15),
Diagnostic(ErrorCode.WRN_NullabilityMismatchInArgument, "new StringOperation()").WithArguments("StringOperation", "IOperation<string>", "operation", "void C.TestB<string>(IOperation<string> operation, out string? result)").WithLocation(10, 15)
);
}

[WorkItem(541810, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/541810")]
[Fact]
public void TestMethodTypeInferenceWhenFixedParameterIsOpenGenericType()
Expand Down