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
Original file line number Diff line number Diff line change
Expand Up @@ -8083,7 +8083,7 @@ private TypeWithState VisitConversion(

TypeWithState resultType = calculateResultType(targetTypeWithNullability, fromExplicitCast, resultState, isSuppressed, targetType);

if (operandType.Type?.IsErrorType() != true && !targetType.IsErrorType())
if (!conversionOperand.HasErrors && !targetType.IsErrorType())
{
// Need to report all warnings that apply since the warnings can be suppressed individually.
if (reportTopLevelWarnings)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2646,18 +2646,12 @@ static void M(C<string> x)
// (6,26): error CS0208: Cannot take the address of, get the size of, or declare a pointer to a managed type ('C<string>')
// C<string?>* y1 = &x;
Diagnostic(ErrorCode.ERR_ManagedAddr, "&x").WithArguments("C<string>").WithLocation(6, 26),
// (6,26): warning CS8619: Nullability of reference types in value of type 'C<string>*' doesn't match target type 'C<string?>*'.
// C<string?>* y1 = &x;
Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "&x").WithArguments("C<string>*", "C<string?>*").WithLocation(6, 26),
// (7,9): error CS0208: Cannot take the address of, get the size of, or declare a pointer to a managed type ('C<string?>')
// C<string?>* y2 = &x!;
Diagnostic(ErrorCode.ERR_ManagedAddr, "C<string?>*").WithArguments("C<string?>").WithLocation(7, 9),
// (7,26): error CS0208: Cannot take the address of, get the size of, or declare a pointer to a managed type ('C<string>')
// C<string?>* y2 = &x!;
Diagnostic(ErrorCode.ERR_ManagedAddr, "&x!").WithArguments("C<string>").WithLocation(7, 26),
// (7,26): warning CS8619: Nullability of reference types in value of type 'C<string>*' doesn't match target type 'C<string?>*'.
// C<string?>* y2 = &x!;
Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "&x!").WithArguments("C<string>*", "C<string?>*").WithLocation(7, 26),
// (7,27): error CS8598: The suppression operator is not allowed in this context
// C<string?>* y2 = &x!;
Diagnostic(ErrorCode.ERR_IllegalSuppression, "x").WithLocation(7, 27)
Expand Down Expand Up @@ -156369,5 +156363,31 @@ public static void M(C c1, C? c2)
Diagnostic(ErrorCode.WRN_NullableValueTypeMayBeNull, "c2").WithLocation(25, 13)
);
}

[Fact, WorkItem(61462, "https://github.com/dotnet/roslyn/issues/61462")]
public void NoNullabilityWarningUnlessAssignmentConversionExists()
{
var comp = CreateCompilation("""
#nullable enable

public static class S
{
public const string A = "a";
}

public class C
{
public (string, string) M()
{
return ("a", S.B);
}
}
""");
comp.VerifyDiagnostics(
// (12,24): error CS0117: 'S' does not contain a definition for 'B'
// return ("a", S.B);
Diagnostic(ErrorCode.ERR_NoSuchMember, "B").WithArguments("S", "B").WithLocation(12, 24)
);
}
}
}