Skip to content
Merged
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
12 changes: 10 additions & 2 deletions src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3160,11 +3160,18 @@ void visitOperandConversion(
ParameterSymbol parameter,
TypeWithState operandType)
{
TypeWithAnnotations targetTypeWithNullability = parameter.TypeWithAnnotations;
Copy link
Member

@333fred 333fred Apr 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

targetTypeWithNullability [](start = 40, length = 25)

Nit: Not a fan of the naming. Nullability in this file generally means either annotation state or flow state. This is really possiblyLiftedTargetType. #ByDesign

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name matches parameter name of the VisitConversion method that is called below.


In reply to: 405826407 [](ancestors = 405826407)


if (isLifted && targetTypeWithNullability.Type.IsNonNullableValueType())
{
targetTypeWithNullability = TypeWithAnnotations.Create(MakeNullableOf(targetTypeWithNullability));
}

_ = VisitConversion(
expr as BoundConversion,
operand,
conversion,
parameter.TypeWithAnnotations,
targetTypeWithNullability,
operandType,
checkConversion: true,
fromExplicitCast: false,
Expand Down Expand Up @@ -7581,7 +7588,8 @@ private void ReportNullabilityMismatchInArgument(SyntaxNode argument, TypeSymbol
private void ReportNullabilityMismatchInArgument(Location argument, TypeSymbol argumentType, ParameterSymbol parameterOpt, TypeSymbol parameterType, bool forOutput)
{
ReportDiagnostic(forOutput ? ErrorCode.WRN_NullabilityMismatchInArgumentForOutput : ErrorCode.WRN_NullabilityMismatchInArgument,
argument, argumentType, parameterType,
argument, argumentType,
parameterOpt?.Type.IsNonNullableValueType() == true && parameterType.IsNullableType() ? parameterOpt.Type : parameterType, // Compensate for operator lifting
GetParameterAsDiagnosticArgument(parameterOpt),
GetContainingSymbolAsDiagnosticArgument(parameterOpt));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121902,6 +121902,92 @@ static void M<T>(
comp.VerifyDiagnostics();
}

[Fact]
[WorkItem(35057, "https://github.com/dotnet/roslyn/issues/39361")]
public void Operator_11()
{
var source =
@"
#nullable enable

using System;

struct S
{
public static implicit operator DateTime?(S? value) => default;

bool M1(S? x1, DateTime y1)
{
return x1 == y1;
}

bool M2(DateTime? x2, DateTime y2)
{
return x2 == y2;
}

bool M3(DateTime x3, DateTime? y3)
{
return x3 == y3;
}

bool M4(DateTime x4, S? y4)
{
return x4 == y4;
}

bool M5(DateTime? x5, DateTime? y5)
{
return x5 == y5;
}

bool M6(S? x6, DateTime? y6)
{
return x6 == y6;
}

bool M7(DateTime? x7, S? y7)
Copy link
Member

@333fred 333fred Apr 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a case for DateTime x8, S y8 #Resolved

{
return x7 == y7;
}

bool M8(DateTime x8, S y8)
{
return x8 == y8;
}

bool M9(S x9, DateTime y9)
{
return x9 == y9;
}
}
";
var comp = CreateCompilation(source);
comp.VerifyDiagnostics();
}

[Fact]
[WorkItem(35057, "https://github.com/dotnet/roslyn/issues/39361")]
public void Operator_12()
{
var source =
@"
#nullable enable

struct S
{
public static bool operator-(S value) => default;

bool? M1(S? x1)
{
return -x1;
}
}
";
var comp = CreateCompilation(source);
comp.VerifyDiagnostics();
}

[Theory]
[InlineData("object.Equals")]
[InlineData("object.ReferenceEquals")]
Expand Down