diff --git a/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs b/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs index cb06ce1c35d30..1850321cbe1cb 100644 --- a/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs +++ b/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs @@ -5772,6 +5772,11 @@ void makeAndAdjustReceiverSlot(BoundExpression receiver) if (isRef) { + Debug.Assert(node is not BoundConditionalOperator { WasTargetTyped: true }, """ + Unexpected ref target typed conditional operator. + Should not do type inference below in this case. + """); + TypeWithAnnotations consequenceLValue; TypeWithAnnotations alternativeLValue; @@ -5780,20 +5785,28 @@ void makeAndAdjustReceiverSlot(BoundExpression receiver) (alternativeLValue, alternativeRValue) = visitConditionalRefOperand(alternativeState, originalAlternative); Join(ref this.State, ref consequenceState); + var lValueAnnotation = consequenceLValue.NullableAnnotation.EnsureCompatible(alternativeLValue.NullableAnnotation); + var rValueState = consequenceRValue.State.Join(alternativeRValue.State); + TypeSymbol? refResultType = node.Type?.SetUnknownNullabilityForReferenceTypes(); if (IsNullabilityMismatch(consequenceLValue, alternativeLValue)) { - // l-value types must match - ReportNullabilityMismatchInAssignment(node.Syntax, consequenceLValue, alternativeLValue); + // If there is a mismatch between the operands, use type inference to determine the target type. + BoundExpression consequencePlaceholder = CreatePlaceholderIfNecessary(originalConsequence, consequenceLValue); + BoundExpression alternativePlaceholder = CreatePlaceholderIfNecessary(originalAlternative, alternativeLValue); + var discardedUseSiteInfo = CompoundUseSiteInfo.Discarded; + refResultType = BestTypeInferrer.InferBestTypeForConditionalOperator(consequencePlaceholder, alternativePlaceholder, _conversions, out _, ref discardedUseSiteInfo); + + // Report warning for each operand that is not convertible to the target type. + var refResultTypeWithAnnotations = TypeWithAnnotations.Create(refResultType, lValueAnnotation); + reportMismatchIfNecessary(originalConsequence, consequenceLValue, refResultTypeWithAnnotations); + reportMismatchIfNecessary(originalAlternative, alternativeLValue, refResultTypeWithAnnotations); } else if (!node.HasErrors) { refResultType = consequenceRValue.Type!.MergeEquivalentTypes(alternativeRValue.Type, VarianceKind.None); } - var lValueAnnotation = consequenceLValue.NullableAnnotation.EnsureCompatible(alternativeLValue.NullableAnnotation); - var rValueState = consequenceRValue.State.Join(alternativeRValue.State); - SetResult(node, TypeWithState.Create(refResultType, rValueState), TypeWithAnnotations.Create(refResultType, lValueAnnotation)); return null; } @@ -5957,6 +5970,14 @@ void addConvertArmsAsCompletion( TypeWithAnnotations lValueType = VisitLvalueWithAnnotations(operand); return (lValueType, ResultType); } + + void reportMismatchIfNecessary(BoundExpression node, TypeWithAnnotations source, TypeWithAnnotations destination) + { + if (!node.IsSuppressed && IsNullabilityMismatch(source, destination)) + { + ReportNullabilityMismatchInAssignment(node.Syntax, source, destination); + } + } } private TypeWithState ConvertConditionalOperandOrSwitchExpressionArmResult( @@ -10890,7 +10911,8 @@ public override void VisitForEachIterationVariables(BoundForEachStatement node) if (iterationVariable.IsRef) { // foreach (ref DestinationType variable in collection) - if (IsNullabilityMismatch(sourceType, destinationType)) + if (node.Expression is not BoundConversion { Operand.IsSuppressed: true } && + IsNullabilityMismatch(sourceType, destinationType)) { var foreachSyntax = (ForEachStatementSyntax)node.Syntax; ReportNullabilityMismatchInAssignment(foreachSyntax.Type, sourceType, destinationType); diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs index 1de85b8adc7bc..14a06faf7fb37 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs @@ -3244,6 +3244,7 @@ public struct StructEnum comp.VerifyDiagnostics(expected); } } + [Fact] public void RefAssignment_Inferred() { @@ -53204,67 +53205,127 @@ static void F1(bool b, ref string? x1, ref string y1) static void F2(bool b, ref I x2, ref I y2) { (b ? ref x2 : ref x2)/*T:I!*/.P.ToString(); // 6 - (b ? ref y2 : ref x2)/*T:I!*/.P.ToString(); // 7 - (b ? ref x2 : ref y2)/*T:I!*/.P.ToString(); // 8, 9 + (b ? ref y2 : ref x2)/*T:I!*/.P.ToString(); // 7 + (b ? ref x2 : ref y2)/*T:I!*/.P.ToString(); // 8 (b ? ref y2 : ref y2)/*T:I!*/.P.ToString(); } static void F3(bool b, ref IIn x3, ref IIn y3) { (b ? ref x3 : ref x3)/*T:IIn!*/.ToString(); - (b ? ref y3 : ref x3)/*T:IIn!*/.ToString(); // 10 - (b ? ref x3 : ref y3)/*T:IIn!*/.ToString(); // 11 + (b ? ref y3 : ref x3)/*T:IIn!*/.ToString(); // 9 + (b ? ref x3 : ref y3)/*T:IIn!*/.ToString(); // 10 (b ? ref y3 : ref y3)/*T:IIn!*/.ToString(); } static void F4(bool b, ref IOut x4, ref IOut y4) { - (b ? ref x4 : ref x4)/*T:IOut!*/.P.ToString(); // 12 - (b ? ref y4 : ref x4)/*T:IOut!*/.P.ToString(); // 13 - (b ? ref x4 : ref y4)/*T:IOut!*/.P.ToString(); // 14 + (b ? ref x4 : ref x4)/*T:IOut!*/.P.ToString(); // 11 + (b ? ref y4 : ref x4)/*T:IOut!*/.P.ToString(); // 12, 13 + (b ? ref x4 : ref y4)/*T:IOut!*/.P.ToString(); // 14, 15 (b ? ref y4 : ref y4)/*T:IOut!*/.P.ToString(); } }"; var comp = CreateCompilation(source, options: WithNullableEnable()); comp.VerifyTypes(); comp.VerifyDiagnostics( - // (8,10): warning CS8602: Possible dereference of a null reference. + // (8,10): warning CS8602: Dereference of a possibly null reference. // (b ? ref x1 : ref x1)/*T:string?*/.ToString(); // 1 Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "b ? ref x1 : ref x1").WithLocation(8, 10), - // (9,10): warning CS8619: Nullability of reference types in value of type 'string?' doesn't match target type 'string'. - // (b ? ref x1 : ref y1)/*T:string?*/.ToString(); // 2, 3 - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref x1 : ref y1").WithArguments("string?", "string").WithLocation(9, 10), - // (9,10): warning CS8602: Possible dereference of a null reference. + // (9,10): warning CS8602: Dereference of a possibly null reference. // (b ? ref x1 : ref y1)/*T:string?*/.ToString(); // 2, 3 Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "b ? ref x1 : ref y1").WithLocation(9, 10), - // (10,10): warning CS8619: Nullability of reference types in value of type 'string' doesn't match target type 'string?'. - // (b ? ref y1 : ref x1)/*T:string?*/.ToString(); // 4, 5 - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref y1 : ref x1").WithArguments("string", "string?").WithLocation(10, 10), - // (10,10): warning CS8602: Possible dereference of a null reference. + // (9,18): warning CS8619: Nullability of reference types in value of type 'string?' doesn't match target type 'string'. + // (b ? ref x1 : ref y1)/*T:string?*/.ToString(); // 2, 3 + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "x1").WithArguments("string?", "string").WithLocation(9, 18), + // (10,10): warning CS8602: Dereference of a possibly null reference. // (b ? ref y1 : ref x1)/*T:string?*/.ToString(); // 4, 5 Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "b ? ref y1 : ref x1").WithLocation(10, 10), - // (15,9): warning CS8602: Possible dereference of a null reference. + // (10,27): warning CS8619: Nullability of reference types in value of type 'string?' doesn't match target type 'string'. + // (b ? ref y1 : ref x1)/*T:string?*/.ToString(); // 4, 5 + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "x1").WithArguments("string?", "string").WithLocation(10, 27), + // (15,9): warning CS8602: Dereference of a possibly null reference. // (b ? ref x2 : ref x2)/*T:I!*/.P.ToString(); // 6 Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "(b ? ref x2 : ref x2)/*T:I!*/.P").WithLocation(15, 9), - // (16,10): warning CS8619: Nullability of reference types in value of type 'I' doesn't match target type 'I'. - // (b ? ref y2 : ref x2)/*T:I!*/.P.ToString(); // 7 - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref y2 : ref x2").WithArguments("I", "I").WithLocation(16, 10), - // (17,10): warning CS8619: Nullability of reference types in value of type 'I' doesn't match target type 'I'. - // (b ? ref x2 : ref y2)/*T:I!*/.P.ToString(); // 8, 9 - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref x2 : ref y2").WithArguments("I", "I").WithLocation(17, 10), - // (23,10): warning CS8619: Nullability of reference types in value of type 'IIn' doesn't match target type 'IIn'. - // (b ? ref y3 : ref x3)/*T:IIn!*/.ToString(); // 10 - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref y3 : ref x3").WithArguments("IIn", "IIn").WithLocation(23, 10), - // (24,10): warning CS8619: Nullability of reference types in value of type 'IIn' doesn't match target type 'IIn'. - // (b ? ref x3 : ref y3)/*T:IIn!*/.ToString(); // 11 - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref x3 : ref y3").WithArguments("IIn", "IIn").WithLocation(24, 10), - // (29,9): warning CS8602: Possible dereference of a null reference. - // (b ? ref x4 : ref x4)/*T:IOut!*/.P.ToString(); // 12 + // (16,27): warning CS8619: Nullability of reference types in value of type 'I' doesn't match target type 'I'. + // (b ? ref y2 : ref x2)/*T:I!*/.P.ToString(); // 7 + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "x2").WithArguments("I", "I").WithLocation(16, 27), + // (17,18): warning CS8619: Nullability of reference types in value of type 'I' doesn't match target type 'I'. + // (b ? ref x2 : ref y2)/*T:I!*/.P.ToString(); // 8 + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "x2").WithArguments("I", "I").WithLocation(17, 18), + // (23,27): warning CS8619: Nullability of reference types in value of type 'IIn' doesn't match target type 'IIn'. + // (b ? ref y3 : ref x3)/*T:IIn!*/.ToString(); // 9 + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "x3").WithArguments("IIn", "IIn").WithLocation(23, 27), + // (24,18): warning CS8619: Nullability of reference types in value of type 'IIn' doesn't match target type 'IIn'. + // (b ? ref x3 : ref y3)/*T:IIn!*/.ToString(); // 10 + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "x3").WithArguments("IIn", "IIn").WithLocation(24, 18), + // (29,9): warning CS8602: Dereference of a possibly null reference. + // (b ? ref x4 : ref x4)/*T:IOut!*/.P.ToString(); // 11 Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "(b ? ref x4 : ref x4)/*T:IOut!*/.P").WithLocation(29, 9), - // (30,10): warning CS8619: Nullability of reference types in value of type 'IOut' doesn't match target type 'IOut'. - // (b ? ref y4 : ref x4)/*T:IOut!*/.P.ToString(); // 13 - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref y4 : ref x4").WithArguments("IOut", "IOut").WithLocation(30, 10), - // (31,10): warning CS8619: Nullability of reference types in value of type 'IOut' doesn't match target type 'IOut'. - // (b ? ref x4 : ref y4)/*T:IOut!*/.P.ToString(); // 14, 15 - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref x4 : ref y4").WithArguments("IOut", "IOut").WithLocation(31, 10)); + // (30,9): warning CS8602: Dereference of a possibly null reference. + // (b ? ref y4 : ref x4)/*T:IOut!*/.P.ToString(); // 12, 13 + Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "(b ? ref y4 : ref x4)/*T:IOut!*/.P").WithLocation(30, 9), + // (30,18): warning CS8619: Nullability of reference types in value of type 'IOut' doesn't match target type 'IOut'. + // (b ? ref y4 : ref x4)/*T:IOut!*/.P.ToString(); // 12, 13 + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "y4").WithArguments("IOut", "IOut").WithLocation(30, 18), + // (31,9): warning CS8602: Dereference of a possibly null reference. + // (b ? ref x4 : ref y4)/*T:IOut!*/.P.ToString(); // 14, 15 + Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "(b ? ref x4 : ref y4)/*T:IOut!*/.P").WithLocation(31, 9), + // (31,27): warning CS8619: Nullability of reference types in value of type 'IOut' doesn't match target type 'IOut'. + // (b ? ref x4 : ref y4)/*T:IOut!*/.P.ToString(); // 14, 15 + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "y4").WithArguments("IOut", "IOut").WithLocation(31, 27)); + } + + [ConditionalFact(typeof(NoUsedAssembliesValidation), Reason = "https://github.com/dotnet/roslyn/issues/75023")] + [WorkItem("https://github.com/dotnet/roslyn/issues/73928")] + public void ConditionalOperator_RefAssignment() + { + var source = """ + #nullable enable + class C + { + static void M1(bool b, ref string? x1, ref string y1, ref string? x2, ref string y2) + { + (b ? ref x1 : ref y1) = ref x2; + (b ? ref x1 : ref y1) = ref y2; + + (b ? ref x1! : ref y1) = ref x2; + (b ? ref x1! : ref y1) = ref y2; + + (b ? ref y1 : ref x1) = ref x2; + (b ? ref y1 : ref x1) = ref y2; + + (b ? ref y1 : ref x1!) = ref x2; + (b ? ref y1 : ref x1!) = ref y2; + + (b ? ref x1! : ref y1) = ref x2!; + (b ? ref y1 : ref x1!) = ref x2!; + } + } + """; + CreateCompilation(source).VerifyDiagnostics( + // (6,18): warning CS8619: Nullability of reference types in value of type 'string?' doesn't match target type 'string'. + // (b ? ref x1 : ref y1) = ref x2; + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "x1").WithArguments("string?", "string").WithLocation(6, 18), + // (6,37): warning CS8619: Nullability of reference types in value of type 'string?' doesn't match target type 'string'. + // (b ? ref x1 : ref y1) = ref x2; + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "x2").WithArguments("string?", "string").WithLocation(6, 37), + // (7,18): warning CS8619: Nullability of reference types in value of type 'string?' doesn't match target type 'string'. + // (b ? ref x1 : ref y1) = ref y2; + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "x1").WithArguments("string?", "string").WithLocation(7, 18), + // (9,38): warning CS8619: Nullability of reference types in value of type 'string?' doesn't match target type 'string'. + // (b ? ref x1! : ref y1) = ref x2; + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "x2").WithArguments("string?", "string").WithLocation(9, 38), + // (12,27): warning CS8619: Nullability of reference types in value of type 'string?' doesn't match target type 'string'. + // (b ? ref y1 : ref x1) = ref x2; + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "x1").WithArguments("string?", "string").WithLocation(12, 27), + // (12,37): warning CS8619: Nullability of reference types in value of type 'string?' doesn't match target type 'string'. + // (b ? ref y1 : ref x1) = ref x2; + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "x2").WithArguments("string?", "string").WithLocation(12, 37), + // (13,27): warning CS8619: Nullability of reference types in value of type 'string?' doesn't match target type 'string'. + // (b ? ref y1 : ref x1) = ref y2; + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "x1").WithArguments("string?", "string").WithLocation(13, 27), + // (15,38): warning CS8619: Nullability of reference types in value of type 'string?' doesn't match target type 'string'. + // (b ? ref y1 : ref x1!) = ref x2; + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "x2").WithArguments("string?", "string").WithLocation(15, 38)); } [Fact] @@ -53306,12 +53367,12 @@ void M1(bool b, string? s) void M(bool b, string? s) { - _ = (b ? ref D2(s) : ref D2(s!)) /*T:C.MyDelegate!*/; // 9 - _ = (b ? ref D2(s!) : ref D2(s)) /*T:C.MyDelegate!*/; // 10 - _ = (true ? ref D2(s) : ref D2(s!)) /*T:C.MyDelegate!*/; // 11 + _ = (b ? ref D2(s) : ref D2(s!)) /*T:C.MyDelegate!*/; // 9 + _ = (b ? ref D2(s!) : ref D2(s)) /*T:C.MyDelegate!*/; // 10 + _ = (true ? ref D2(s) : ref D2(s!)) /*T:C.MyDelegate!*/; // 11 _ = (true ? ref D2(s!) : ref D2(s)) /*T:C.MyDelegate!*/; _ = (false ? ref D2(s) : ref D2(s!)) /*T:C.MyDelegate!*/; - _ = (false ? ref D2(s!) : ref D2(s)) /*T:C.MyDelegate!*/; // 12 + _ = (false ? ref D2(s!) : ref D2(s)) /*T:C.MyDelegate!*/; // 12 } }"; @@ -53322,18 +53383,18 @@ void M(bool b, string? s) var comp = CreateCompilation(source, options: WithNullableEnable()); comp.VerifyTypes(); comp.VerifyDiagnostics( - // (36,14): warning CS8619: Nullability of reference types in value of type 'C.MyDelegate' doesn't match target type 'C.MyDelegate'. - // _ = (b ? ref D2(s) : ref D2(s!)) /*T:C.MyDelegate!*/; // 9 - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref D2(s) : ref D2(s!)").WithArguments("C.MyDelegate", "C.MyDelegate").WithLocation(36, 14), - // (37,14): warning CS8619: Nullability of reference types in value of type 'C.MyDelegate' doesn't match target type 'C.MyDelegate'. - // _ = (b ? ref D2(s!) : ref D2(s)) /*T:C.MyDelegate!*/; // 10 - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref D2(s!) : ref D2(s)").WithArguments("C.MyDelegate", "C.MyDelegate").WithLocation(37, 14), - // (38,14): warning CS8619: Nullability of reference types in value of type 'C.MyDelegate' doesn't match target type 'C.MyDelegate'. - // _ = (true ? ref D2(s) : ref D2(s!)) /*T:C.MyDelegate!*/; // 11 - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "true ? ref D2(s) : ref D2(s!)").WithArguments("C.MyDelegate", "C.MyDelegate").WithLocation(38, 14), - // (41,14): warning CS8619: Nullability of reference types in value of type 'C.MyDelegate' doesn't match target type 'C.MyDelegate'. - // _ = (false ? ref D2(s!) : ref D2(s)) /*T:C.MyDelegate!*/; // unexpected type - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "false ? ref D2(s!) : ref D2(s)").WithArguments("C.MyDelegate", "C.MyDelegate").WithLocation(41, 14) + // (36,22): warning CS8619: Nullability of reference types in value of type 'C.MyDelegate' doesn't match target type 'C.MyDelegate'. + // _ = (b ? ref D2(s) : ref D2(s!)) /*T:C.MyDelegate!*/; // 9 + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "D2(s)").WithArguments("C.MyDelegate", "C.MyDelegate").WithLocation(36, 22), + // (37,35): warning CS8619: Nullability of reference types in value of type 'C.MyDelegate' doesn't match target type 'C.MyDelegate'. + // _ = (b ? ref D2(s!) : ref D2(s)) /*T:C.MyDelegate!*/; // 10 + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "D2(s)").WithArguments("C.MyDelegate", "C.MyDelegate").WithLocation(37, 35), + // (38,25): warning CS8619: Nullability of reference types in value of type 'C.MyDelegate' doesn't match target type 'C.MyDelegate'. + // _ = (true ? ref D2(s) : ref D2(s!)) /*T:C.MyDelegate!*/; // 11 + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "D2(s)").WithArguments("C.MyDelegate", "C.MyDelegate").WithLocation(38, 25), + // (41,39): warning CS8619: Nullability of reference types in value of type 'C.MyDelegate' doesn't match target type 'C.MyDelegate'. + // _ = (false ? ref D2(s!) : ref D2(s)) /*T:C.MyDelegate!*/; // 12 + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "D2(s)").WithArguments("C.MyDelegate", "C.MyDelegate").WithLocation(41, 39) ); } @@ -53393,26 +53454,32 @@ class C { static void M1(bool b, string s, string? s2) { - (b ? ref Create(s, s2) : ref Create(s2, s)) /*T:C!*/ = null; - (b ? ref Create(s2, s) : ref Create(s, s2)) /*T:C!*/ = null; + (b ? ref Create(s, s2) : ref Create(s2, s)) /*T:C!*/ = null; + (b ? ref Create(s2, s) : ref Create(s, s2)) /*T:C!*/ = null; } static ref C Create(U1 x, U2 y) => throw null!; }"; var comp = CreateCompilation(source, options: WithNullableEnable()); comp.VerifyTypes(); comp.VerifyDiagnostics( - // (6,10): warning CS8619: Nullability of reference types in value of type 'C' doesn't match target type 'C'. - // (b ? ref Create(s, s2) : ref Create(s2, s)) /*T:C!*/ = null; - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref Create(s, s2) : ref Create(s2, s)").WithArguments("C", "C").WithLocation(6, 10), - // (6,80): warning CS8625: Cannot convert null literal to non-nullable reference type. - // (b ? ref Create(s, s2) : ref Create(s2, s)) /*T:C!*/ = null; - Diagnostic(ErrorCode.WRN_NullAsNonNullable, "null").WithLocation(6, 80), - // (7,10): warning CS8619: Nullability of reference types in value of type 'C' doesn't match target type 'C'. - // (b ? ref Create(s2, s) : ref Create(s, s2)) /*T:C!*/ = null; - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref Create(s2, s) : ref Create(s, s2)").WithArguments("C", "C").WithLocation(7, 10), - // (7,80): warning CS8625: Cannot convert null literal to non-nullable reference type. - // (b ? ref Create(s2, s) : ref Create(s, s2)) /*T:C!*/ = null; - Diagnostic(ErrorCode.WRN_NullAsNonNullable, "null").WithLocation(7, 80) + // (6,18): warning CS8619: Nullability of reference types in value of type 'C' doesn't match target type 'C'. + // (b ? ref Create(s, s2) : ref Create(s2, s)) /*T:C!*/ = null; + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "Create(s, s2)").WithArguments("C", "C").WithLocation(6, 18), + // (6,38): warning CS8619: Nullability of reference types in value of type 'C' doesn't match target type 'C'. + // (b ? ref Create(s, s2) : ref Create(s2, s)) /*T:C!*/ = null; + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "Create(s2, s)").WithArguments("C", "C").WithLocation(6, 38), + // (6,82): warning CS8625: Cannot convert null literal to non-nullable reference type. + // (b ? ref Create(s, s2) : ref Create(s2, s)) /*T:C!*/ = null; + Diagnostic(ErrorCode.WRN_NullAsNonNullable, "null").WithLocation(6, 82), + // (7,18): warning CS8619: Nullability of reference types in value of type 'C' doesn't match target type 'C'. + // (b ? ref Create(s2, s) : ref Create(s, s2)) /*T:C!*/ = null; + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "Create(s2, s)").WithArguments("C", "C").WithLocation(7, 18), + // (7,38): warning CS8619: Nullability of reference types in value of type 'C' doesn't match target type 'C'. + // (b ? ref Create(s2, s) : ref Create(s, s2)) /*T:C!*/ = null; + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "Create(s, s2)").WithArguments("C", "C").WithLocation(7, 38), + // (7,82): warning CS8625: Cannot convert null literal to non-nullable reference type. + // (b ? ref Create(s2, s) : ref Create(s, s2)) /*T:C!*/ = null; + Diagnostic(ErrorCode.WRN_NullAsNonNullable, "null").WithLocation(7, 82) ); } @@ -53445,30 +53512,30 @@ static void F1(bool b, ref string? x1, ref string y1) // (6,14): warning CS8625: Cannot convert null literal to non-nullable reference type. // y1 = null; // 1 Diagnostic(ErrorCode.WRN_NullAsNonNullable, "null").WithLocation(6, 14), - // (7,10): warning CS8602: Possible dereference of a null reference. + // (7,10): warning CS8602: Dereference of a possibly null reference. // (b ? ref x1 : ref x1)/*T:string?*/.ToString(); // 2 Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "b ? ref x1 : ref x1").WithLocation(7, 10), - // (8,10): warning CS8619: Nullability of reference types in value of type 'string?' doesn't match target type 'string'. - // (b ? ref x1 : ref y1)/*T:string?*/.ToString(); // 3, 4 - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref x1 : ref y1").WithArguments("string?", "string").WithLocation(8, 10), - // (8,10): warning CS8602: Possible dereference of a null reference. + // (8,10): warning CS8602: Dereference of a possibly null reference. // (b ? ref x1 : ref y1)/*T:string?*/.ToString(); // 3, 4 Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "b ? ref x1 : ref y1").WithLocation(8, 10), - // (9,10): warning CS8619: Nullability of reference types in value of type 'string' doesn't match target type 'string?'. - // (b ? ref y1 : ref x1)/*T:string?*/.ToString(); // 5, 6 - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref y1 : ref x1").WithArguments("string", "string?").WithLocation(9, 10), - // (9,10): warning CS8602: Possible dereference of a null reference. + // (8,18): warning CS8619: Nullability of reference types in value of type 'string?' doesn't match target type 'string'. + // (b ? ref x1 : ref y1)/*T:string?*/.ToString(); // 3, 4 + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "x1").WithArguments("string?", "string").WithLocation(8, 18), + // (9,10): warning CS8602: Dereference of a possibly null reference. // (b ? ref y1 : ref x1)/*T:string?*/.ToString(); // 5, 6 Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "b ? ref y1 : ref x1").WithLocation(9, 10), - // (10,10): warning CS8602: Possible dereference of a null reference. + // (9,27): warning CS8619: Nullability of reference types in value of type 'string?' doesn't match target type 'string'. + // (b ? ref y1 : ref x1)/*T:string?*/.ToString(); // 5, 6 + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "x1").WithArguments("string?", "string").WithLocation(9, 27), + // (10,10): warning CS8602: Dereference of a possibly null reference. // (b ? ref y1 : ref y1)/*T:string?*/.ToString(); // 7 Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "b ? ref y1 : ref y1").WithLocation(10, 10), - // (15,10): warning CS8619: Nullability of reference types in value of type 'string?' doesn't match target type 'string'. + // (15,18): warning CS8619: Nullability of reference types in value of type 'string?' doesn't match target type 'string'. // (b ? ref x1 : ref y1)/*T:string!*/.ToString(); // 8 - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref x1 : ref y1").WithArguments("string?", "string").WithLocation(15, 10), - // (16,10): warning CS8619: Nullability of reference types in value of type 'string' doesn't match target type 'string?'. + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "x1").WithArguments("string?", "string").WithLocation(15, 18), + // (16,27): warning CS8619: Nullability of reference types in value of type 'string?' doesn't match target type 'string'. // (b ? ref y1 : ref x1)/*T:string!*/.ToString(); // 9 - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref y1 : ref x1").WithArguments("string", "string?").WithLocation(16, 10) + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "x1").WithArguments("string?", "string").WithLocation(16, 27) ); } @@ -53608,17 +53675,17 @@ static void F1(bool b) var comp = CreateCompilation(source, options: WithNullableEnable()); comp.VerifyTypes(); comp.VerifyDiagnostics( - // (6,10): warning CS8619: Nullability of reference types in value of type 'string?' doesn't match target type 'string'. + // (6,18): warning CS8619: Nullability of reference types in value of type 'string?' doesn't match target type 'string'. // (b ? ref M1(false ? 1 : throw new System.Exception()) : ref M2(2)) /*T:string!*/ = null; // 1, 2 - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref M1(false ? 1 : throw new System.Exception()) : ref M2(2)").WithArguments("string?", "string").WithLocation(6, 10), + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "M1(false ? 1 : throw new System.Exception())").WithArguments("string?", "string").WithLocation(6, 18), // (6,92): warning CS8625: Cannot convert null literal to non-nullable reference type. // (b ? ref M1(false ? 1 : throw new System.Exception()) : ref M2(2)) /*T:string!*/ = null; // 1, 2 Diagnostic(ErrorCode.WRN_NullAsNonNullable, "null").WithLocation(6, 92), - // (7,10): warning CS8619: Nullability of reference types in value of type 'string?' doesn't match target type 'string'. - // (b ? ref M1(1) : ref M2(false ? 2 : throw new System.Exception())) /*T:string?*/ = null; // 3, 4 - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref M1(1) : ref M2(false ? 2 : throw new System.Exception())").WithArguments("string?", "string").WithLocation(7, 10), + // (7,18): warning CS8619: Nullability of reference types in value of type 'string?' doesn't match target type 'string'. + // (b ? ref M1(1) : ref M2(false ? 2 : throw new System.Exception())) /*T:string!*/ = null; // 3, 4 + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "M1(1)").WithArguments("string?", "string").WithLocation(7, 18), // (7,92): warning CS8625: Cannot convert null literal to non-nullable reference type. - // (b ? ref M1(1) : ref M2(false ? 2 : throw new System.Exception())) /*T:string?*/ = null; // 3, 4 + // (b ? ref M1(1) : ref M2(false ? 2 : throw new System.Exception())) /*T:string!*/ = null; // 3, 4 Diagnostic(ErrorCode.WRN_NullAsNonNullable, "null").WithLocation(7, 92) ); } @@ -53666,30 +53733,30 @@ static void F1(bool b, ref string? x1, ref string y1) var comp = CreateCompilation(source, options: WithNullableEnable()); comp.VerifyTypes(); comp.VerifyDiagnostics( - // (7,10): warning CS8619: Nullability of reference types in value of type 'string?' doesn't match target type 'string'. + // (7,29): warning CS8619: Nullability of reference types in value of type 'string?' doesn't match target type 'string'. // ((b && false) ? ref x1 : ref y1)/*T:string!*/ = null; // 1, 2 - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "(b && false) ? ref x1 : ref y1").WithArguments("string?", "string").WithLocation(7, 10), + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "x1").WithArguments("string?", "string").WithLocation(7, 29), // (7,57): warning CS8625: Cannot convert null literal to non-nullable reference type. // ((b && false) ? ref x1 : ref y1)/*T:string!*/ = null; // 1, 2 Diagnostic(ErrorCode.WRN_NullAsNonNullable, "null").WithLocation(7, 57), - // (8,10): warning CS8619: Nullability of reference types in value of type 'string' doesn't match target type 'string?'. - // ((b && false) ? ref y1 : ref x1)/*T:string?*/ = null; // 3, 4 - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "(b && false) ? ref y1 : ref x1").WithArguments("string", "string?").WithLocation(8, 10), + // (8,38): warning CS8619: Nullability of reference types in value of type 'string?' doesn't match target type 'string'. + // ((b && false) ? ref y1 : ref x1)/*T:string!*/ = null; // 3, 4 + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "x1").WithArguments("string?", "string").WithLocation(8, 38), // (8,57): warning CS8625: Cannot convert null literal to non-nullable reference type. - // ((b && false) ? ref y1 : ref x1)/*T:string?*/ = null; // 3, 4 + // ((b && false) ? ref y1 : ref x1)/*T:string!*/ = null; // 3, 4 Diagnostic(ErrorCode.WRN_NullAsNonNullable, "null").WithLocation(8, 57), // (9,57): warning CS8625: Cannot convert null literal to non-nullable reference type. // ((b && false) ? ref y1 : ref y1)/*T:string!*/ = null; // 5 Diagnostic(ErrorCode.WRN_NullAsNonNullable, "null").WithLocation(9, 57), - // (12,10): warning CS8619: Nullability of reference types in value of type 'string?' doesn't match target type 'string'. - // ((b || true) ? ref x1 : ref y1)/*T:string?*/ = null; // 6, 7 - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "(b || true) ? ref x1 : ref y1").WithArguments("string?", "string").WithLocation(12, 10), + // (12,28): warning CS8619: Nullability of reference types in value of type 'string?' doesn't match target type 'string'. + // ((b || true) ? ref x1 : ref y1)/*T:string!*/ = null; // 6, 7 + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "x1").WithArguments("string?", "string").WithLocation(12, 28), // (12,56): warning CS8625: Cannot convert null literal to non-nullable reference type. - // ((b || true) ? ref x1 : ref y1)/*T:string?*/ = null; // 6, 7 + // ((b || true) ? ref x1 : ref y1)/*T:string!*/ = null; // 6, 7 Diagnostic(ErrorCode.WRN_NullAsNonNullable, "null").WithLocation(12, 56), - // (13,10): warning CS8619: Nullability of reference types in value of type 'string' doesn't match target type 'string?'. + // (13,37): warning CS8619: Nullability of reference types in value of type 'string?' doesn't match target type 'string'. // ((b || true) ? ref y1 : ref x1)/*T:string!*/ = null; // 8, 9 - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "(b || true) ? ref y1 : ref x1").WithArguments("string", "string?").WithLocation(13, 10), + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "x1").WithArguments("string?", "string").WithLocation(13, 37), // (13,56): warning CS8625: Cannot convert null literal to non-nullable reference type. // ((b || true) ? ref y1 : ref x1)/*T:string!*/ = null; // 8, 9 Diagnostic(ErrorCode.WRN_NullAsNonNullable, "null").WithLocation(13, 56), @@ -55045,12 +55112,12 @@ static void F(bool b, object? x, object y) }"; var comp = CreateCompilation(source, options: WithNullableEnable(), references: new[] { ref0 }); comp.VerifyDiagnostics( - // (6,26): warning CS8619: Nullability of reference types in value of type 'object?' doesn't match target type 'object'. + // (6,34): warning CS8619: Nullability of reference types in value of type 'object?' doesn't match target type 'object'. // ref var xy = ref b ? ref x : ref y; // 1 - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref x : ref y").WithArguments("object?", "object").WithLocation(6, 26), - // (8,26): warning CS8619: Nullability of reference types in value of type 'object' doesn't match target type 'object?'. + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "x").WithArguments("object?", "object").WithLocation(6, 34), + // (8,42): warning CS8619: Nullability of reference types in value of type 'object?' doesn't match target type 'object'. // ref var yx = ref b ? ref y : ref x; // 2 - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref y : ref x").WithArguments("object", "object?").WithLocation(8, 26) + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "x").WithArguments("object?", "object").WithLocation(8, 42) ); } @@ -55118,64 +55185,310 @@ static void F3(bool b, IOut x3, IOut y3) }"; var comp = CreateCompilation(source, options: WithNullableEnable(), references: new[] { ref0 }); comp.VerifyDiagnostics( - // (7,26): warning CS8619: Nullability of reference types in value of type 'I' doesn't match target type 'I'. + // (7,43): warning CS8619: Nullability of reference types in value of type 'I' doesn't match target type 'I'. // ref var xy = ref b ? ref x1 : ref y1; // 1 - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref x1 : ref y1").WithArguments("I", "I").WithLocation(7, 26), - // (8,26): warning CS8619: Nullability of reference types in value of type 'I' doesn't match target type 'I?'. + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "y1").WithArguments("I", "I").WithLocation(7, 43), + // (8,43): warning CS8619: Nullability of reference types in value of type 'I?' doesn't match target type 'I'. // ref var xz = ref b ? ref x1 : ref z1; // 2 - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref x1 : ref z1").WithArguments("I", "I?").WithLocation(8, 26), - // (9,26): warning CS8619: Nullability of reference types in value of type 'I' doesn't match target type 'I'. + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "z1").WithArguments("I?", "I").WithLocation(8, 43), + // (9,34): warning CS8619: Nullability of reference types in value of type 'I' doesn't match target type 'I'. // ref var yx = ref b ? ref y1 : ref x1; // 3 - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref y1 : ref x1").WithArguments("I", "I").WithLocation(9, 26), - // (11,26): warning CS8619: Nullability of reference types in value of type 'I' doesn't match target type 'I?'. + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "y1").WithArguments("I", "I").WithLocation(9, 34), + // (11,43): warning CS8619: Nullability of reference types in value of type 'I?' doesn't match target type 'I'. // ref var yz = ref b ? ref y1 : ref z1; // 4 - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref y1 : ref z1").WithArguments("I", "I?").WithLocation(11, 26), - // (12,26): warning CS8619: Nullability of reference types in value of type 'I?' doesn't match target type 'I'. + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "z1").WithArguments("I?", "I").WithLocation(11, 43), + // (12,34): warning CS8619: Nullability of reference types in value of type 'I?' doesn't match target type 'I'. // ref var zx = ref b ? ref z1 : ref x1; // 5 - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref z1 : ref x1").WithArguments("I?", "I").WithLocation(12, 26), - // (13,26): warning CS8619: Nullability of reference types in value of type 'I?' doesn't match target type 'I'. + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "z1").WithArguments("I?", "I").WithLocation(12, 34), + // (13,34): warning CS8619: Nullability of reference types in value of type 'I?' doesn't match target type 'I'. // ref var zy = ref b ? ref z1 : ref y1; // 6 - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref z1 : ref y1").WithArguments("I?", "I").WithLocation(13, 26), - // (20,26): warning CS8619: Nullability of reference types in value of type 'IIn' doesn't match target type 'IIn'. + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "z1").WithArguments("I?", "I").WithLocation(13, 34), + // (20,43): warning CS8619: Nullability of reference types in value of type 'IIn' doesn't match target type 'IIn'. // ref var xy = ref b ? ref x2 : ref y2; // 7 - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref x2 : ref y2").WithArguments("IIn", "IIn").WithLocation(20, 26), - // (21,26): warning CS8619: Nullability of reference types in value of type 'IIn' doesn't match target type 'IIn?'. + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "y2").WithArguments("IIn", "IIn").WithLocation(20, 43), + // (21,43): warning CS8619: Nullability of reference types in value of type 'IIn?' doesn't match target type 'IIn'. // ref var xz = ref b ? ref x2 : ref z2; // 8 - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref x2 : ref z2").WithArguments("IIn", "IIn?").WithLocation(21, 26), - // (22,26): warning CS8619: Nullability of reference types in value of type 'IIn' doesn't match target type 'IIn'. + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "z2").WithArguments("IIn?", "IIn").WithLocation(21, 43), + // (22,34): warning CS8619: Nullability of reference types in value of type 'IIn' doesn't match target type 'IIn'. // ref var yx = ref b ? ref y2 : ref x2; // 9 - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref y2 : ref x2").WithArguments("IIn", "IIn").WithLocation(22, 26), - // (24,26): warning CS8619: Nullability of reference types in value of type 'IIn' doesn't match target type 'IIn?'. + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "y2").WithArguments("IIn", "IIn").WithLocation(22, 34), + // (24,43): warning CS8619: Nullability of reference types in value of type 'IIn?' doesn't match target type 'IIn'. // ref var yz = ref b ? ref y2 : ref z2; // 10 - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref y2 : ref z2").WithArguments("IIn", "IIn?").WithLocation(24, 26), - // (25,26): warning CS8619: Nullability of reference types in value of type 'IIn?' doesn't match target type 'IIn'. + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "z2").WithArguments("IIn?", "IIn").WithLocation(24, 43), + // (25,34): warning CS8619: Nullability of reference types in value of type 'IIn?' doesn't match target type 'IIn'. // ref var zx = ref b ? ref z2 : ref x2; // 11 - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref z2 : ref x2").WithArguments("IIn?", "IIn").WithLocation(25, 26), - // (26,26): warning CS8619: Nullability of reference types in value of type 'IIn?' doesn't match target type 'IIn'. + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "z2").WithArguments("IIn?", "IIn").WithLocation(25, 34), + // (26,34): warning CS8619: Nullability of reference types in value of type 'IIn?' doesn't match target type 'IIn'. // ref var zy = ref b ? ref z2 : ref y2; // 12 - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref z2 : ref y2").WithArguments("IIn?", "IIn").WithLocation(26, 26), - // (33,26): warning CS8619: Nullability of reference types in value of type 'IOut' doesn't match target type 'IOut'. + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "z2").WithArguments("IIn?", "IIn").WithLocation(26, 34), + // (33,34): warning CS8619: Nullability of reference types in value of type 'IOut' doesn't match target type 'IOut'. // ref var xy = ref b ? ref x3 : ref y3; // 13 - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref x3 : ref y3").WithArguments("IOut", "IOut").WithLocation(33, 26), - // (34,26): warning CS8619: Nullability of reference types in value of type 'IOut' doesn't match target type 'IOut?'. + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "x3").WithArguments("IOut", "IOut").WithLocation(33, 34), + // (34,43): warning CS8619: Nullability of reference types in value of type 'IOut?' doesn't match target type 'IOut'. // ref var xz = ref b ? ref x3 : ref z3; // 14 - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref x3 : ref z3").WithArguments("IOut", "IOut?").WithLocation(34, 26), - // (35,26): warning CS8619: Nullability of reference types in value of type 'IOut' doesn't match target type 'IOut'. + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "z3").WithArguments("IOut?", "IOut").WithLocation(34, 43), + // (35,43): warning CS8619: Nullability of reference types in value of type 'IOut' doesn't match target type 'IOut'. // ref var yx = ref b ? ref y3 : ref x3; // 15 - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref y3 : ref x3").WithArguments("IOut", "IOut").WithLocation(35, 26), - // (37,26): warning CS8619: Nullability of reference types in value of type 'IOut' doesn't match target type 'IOut?'. + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "x3").WithArguments("IOut", "IOut").WithLocation(35, 43), + // (37,43): warning CS8619: Nullability of reference types in value of type 'IOut?' doesn't match target type 'IOut'. // ref var yz = ref b ? ref y3 : ref z3; // 17 - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref y3 : ref z3").WithArguments("IOut", "IOut?").WithLocation(37, 26), - // (38,26): warning CS8619: Nullability of reference types in value of type 'IOut?' doesn't match target type 'IOut'. + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "z3").WithArguments("IOut?", "IOut").WithLocation(37, 43), + // (38,34): warning CS8619: Nullability of reference types in value of type 'IOut?' doesn't match target type 'IOut'. // ref var zx = ref b ? ref z3 : ref x3; // 18 - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref z3 : ref x3").WithArguments("IOut?", "IOut").WithLocation(38, 26), - // (39,26): warning CS8619: Nullability of reference types in value of type 'IOut?' doesn't match target type 'IOut'. + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "z3").WithArguments("IOut?", "IOut").WithLocation(38, 34), + // (39,34): warning CS8619: Nullability of reference types in value of type 'IOut?' doesn't match target type 'IOut'. // ref var zy = ref b ? ref z3 : ref y3; // 19 - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref z3 : ref y3").WithArguments("IOut?", "IOut").WithLocation(39, 26) + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "z3").WithArguments("IOut?", "IOut").WithLocation(39, 34) ); comp.VerifyTypes(); } + [Fact] + public void ConditionalOperator_Suppression() + { + var source = """ + #nullable enable + class C + { + object M1(bool b, object? x, object y) => b ? x : y; + object M2(bool b, object? x, object y) => b ? x! : y; + object M3(bool b, object? x, object y) => b ? x : y!; + object M4(bool b, object? x, object y) => b ? x! : y!; + object M5(bool b, object? x, object y) => (b ? x : y)!; + object M6(bool b, object? x, object y) => (b ? x! : y)!; + object M7(bool b, object? x, object y) => (b ? x : y!)!; + object M8(bool b, object? x, object y) => (b ? x! : y!)!; + } + """; + CreateCompilation(source).VerifyDiagnostics( + // (4,47): warning CS8603: Possible null reference return. + // object M1(bool b, object? x, object y) => b ? x : y; + Diagnostic(ErrorCode.WRN_NullReferenceReturn, "b ? x : y").WithLocation(4, 47), + // (6,47): warning CS8603: Possible null reference return. + // object M3(bool b, object? x, object y) => b ? x : y!; + Diagnostic(ErrorCode.WRN_NullReferenceReturn, "b ? x : y!").WithLocation(6, 47)); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/73928")] + public void ConditionalOperator_Suppression_Ref_01() + { + var source = """ + #nullable enable + class C + { + ref object M1(bool b, ref object? x, ref object y) => ref b ? ref x : ref y; + ref object M2(bool b, ref object? x, ref object y) => ref b ? ref x! : ref y; + ref object M3(bool b, ref object? x, ref object y) => ref b ? ref x : ref y!; + ref object M4(bool b, ref object? x, ref object y) => ref b ? ref x! : ref y!; + ref object M5(bool b, ref object? x, ref object y) => ref (b ? ref x : ref y)!; + ref object M6(bool b, ref object? x, ref object y) => ref (b ? ref x! : ref y)!; + ref object M7(bool b, ref object? x, ref object y) => ref (b ? ref x : ref y!)!; + ref object M8(bool b, ref object? x, ref object y) => ref (b ? ref x! : ref y!)!; + } + """; + CreateCompilation(source).VerifyDiagnostics( + // (4,63): warning CS8601: Possible null reference assignment. + // ref object M1(bool b, ref object? x, ref object y) => ref b ? ref x : ref y; + Diagnostic(ErrorCode.WRN_NullReferenceAssignment, "b ? ref x : ref y").WithLocation(4, 63), + // (4,71): warning CS8619: Nullability of reference types in value of type 'object?' doesn't match target type 'object'. + // ref object M1(bool b, ref object? x, ref object y) => ref b ? ref x : ref y; + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "x").WithArguments("object?", "object").WithLocation(4, 71), + // (6,63): warning CS8601: Possible null reference assignment. + // ref object M3(bool b, ref object? x, ref object y) => ref b ? ref x : ref y!; + Diagnostic(ErrorCode.WRN_NullReferenceAssignment, "b ? ref x : ref y!").WithLocation(6, 63), + // (6,71): warning CS8619: Nullability of reference types in value of type 'object?' doesn't match target type 'object'. + // ref object M3(bool b, ref object? x, ref object y) => ref b ? ref x : ref y!; + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "x").WithArguments("object?", "object").WithLocation(6, 71), + // (8,72): warning CS8619: Nullability of reference types in value of type 'object?' doesn't match target type 'object'. + // ref object M5(bool b, ref object? x, ref object y) => ref (b ? ref x : ref y)!; + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "x").WithArguments("object?", "object").WithLocation(8, 72), + // (10,72): warning CS8619: Nullability of reference types in value of type 'object?' doesn't match target type 'object'. + // ref object M7(bool b, ref object? x, ref object y) => ref (b ? ref x : ref y!)!; + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "x").WithArguments("object?", "object").WithLocation(10, 72)); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/73928")] + public void ConditionalOperator_Suppression_Ref_02() + { + var source = """ + #nullable enable + class C + { + ref object? M1(bool b, ref object? x, ref object y) => ref b ? ref x : ref y; + ref object? M2(bool b, ref object? x, ref object y) => ref b ? ref x! : ref y; + ref object? M3(bool b, ref object? x, ref object y) => ref b ? ref x : ref y!; + ref object? M4(bool b, ref object? x, ref object y) => ref b ? ref x! : ref y!; + ref object? M5(bool b, ref object? x, ref object y) => ref (b ? ref x : ref y)!; + ref object? M6(bool b, ref object? x, ref object y) => ref (b ? ref x! : ref y)!; + ref object? M7(bool b, ref object? x, ref object y) => ref (b ? ref x : ref y!)!; + ref object? M8(bool b, ref object? x, ref object y) => ref (b ? ref x! : ref y!)!; + } + """; + CreateCompilation(source).VerifyDiagnostics( + // (4,64): warning CS8619: Nullability of reference types in value of type 'object' doesn't match target type 'object?'. + // ref object? M1(bool b, ref object? x, ref object y) => ref b ? ref x : ref y; + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref x : ref y").WithArguments("object", "object?").WithLocation(4, 64), + // (4,72): warning CS8619: Nullability of reference types in value of type 'object?' doesn't match target type 'object'. + // ref object? M1(bool b, ref object? x, ref object y) => ref b ? ref x : ref y; + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "x").WithArguments("object?", "object").WithLocation(4, 72), + // (5,64): warning CS8619: Nullability of reference types in value of type 'object' doesn't match target type 'object?'. + // ref object? M2(bool b, ref object? x, ref object y) => ref b ? ref x! : ref y; + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref x! : ref y").WithArguments("object", "object?").WithLocation(5, 64), + // (6,64): warning CS8619: Nullability of reference types in value of type 'object' doesn't match target type 'object?'. + // ref object? M3(bool b, ref object? x, ref object y) => ref b ? ref x : ref y!; + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref x : ref y!").WithArguments("object", "object?").WithLocation(6, 64), + // (6,72): warning CS8619: Nullability of reference types in value of type 'object?' doesn't match target type 'object'. + // ref object? M3(bool b, ref object? x, ref object y) => ref b ? ref x : ref y!; + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "x").WithArguments("object?", "object").WithLocation(6, 72), + // (7,64): warning CS8619: Nullability of reference types in value of type 'object' doesn't match target type 'object?'. + // ref object? M4(bool b, ref object? x, ref object y) => ref b ? ref x! : ref y!; + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref x! : ref y!").WithArguments("object", "object?").WithLocation(7, 64), + // (8,73): warning CS8619: Nullability of reference types in value of type 'object?' doesn't match target type 'object'. + // ref object? M5(bool b, ref object? x, ref object y) => ref (b ? ref x : ref y)!; + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "x").WithArguments("object?", "object").WithLocation(8, 73), + // (10,73): warning CS8619: Nullability of reference types in value of type 'object?' doesn't match target type 'object'. + // ref object? M7(bool b, ref object? x, ref object y) => ref (b ? ref x : ref y!)!; + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "x").WithArguments("object?", "object").WithLocation(10, 73)); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/73928")] + public void ConditionalOperator_Suppression_Ref_03() + { + var source = """ + #nullable enable + class C + { + ref object? M1(bool b, ref object? x, ref object y) + { + ref object? y1 = ref y!; + return ref b ? ref x : ref y1; + } + ref object M2(bool b, ref object? x, ref object y) + { + ref object x1 = ref x!; + return ref b ? ref x1 : ref y; + } + } + """; + CreateCompilation(source).VerifyDiagnostics(); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/73928")] + public void ConditionalOperator_Suppression_Ref_04() + { + var source = """ + #nullable enable + class C + { + ref object M1(bool b, ref object? x, ref object? y) => ref b ? ref x : ref y; + ref object M2(bool b, ref object? x, ref object? y) => ref (b ? ref x : ref y)!; + ref object? M3(bool b, ref object x, ref object y) => ref b ? ref x : ref y; + ref object? M4(bool b, ref object x, ref object y) => ref (b ? ref x : ref y)!; + } + """; + CreateCompilation(source).VerifyDiagnostics( + // (4,64): warning CS8619: Nullability of reference types in value of type 'object?' doesn't match target type 'object'. + // ref object M1(bool b, ref object? x, ref object? y) => ref b ? ref x : ref y; + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref x : ref y").WithArguments("object?", "object").WithLocation(4, 64), + // (6,63): warning CS8619: Nullability of reference types in value of type 'object' doesn't match target type 'object?'. + // ref object? M3(bool b, ref object x, ref object y) => ref b ? ref x : ref y; + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref x : ref y").WithArguments("object", "object?").WithLocation(6, 63)); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/73928")] + public void ConditionalOperator_Suppression_Ref_05() + { + var source = """ + #nullable enable + class C + { + ref object? M1(bool b, ref object? x, ref object? y) => ref b ? ref x : ref y; + ref object? M2(bool b, ref object? x, ref object? y) => ref (b ? ref x : ref y)!; + ref object M3(bool b, ref object x, ref object y) => ref b ? ref x : ref y; + ref object M4(bool b, ref object x, ref object y) => ref (b ? ref x : ref y)!; + } + """; + CreateCompilation(source).VerifyDiagnostics(); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/73928")] + public void ConditionalOperator_Suppression_Ref_Nested_01() + { + var source = """ + #nullable enable + using System.Collections.Generic; + class C + { + ref List? M1(bool b, ref List? x, ref List? y) => ref b ? ref x : ref y; + ref List? M2(bool b, ref List? x, ref List? y) => ref b ? ref x! : ref y; + ref List? M3(bool b, ref List? x, ref List? y) => ref b ? ref x : ref y!; + ref List? M4(bool b, ref List? x, ref List? y) => ref b ? ref x! : ref y!; + ref List? M5(bool b, ref List? x, ref List? y) => ref (b ? ref x : ref y)!; + ref List? M6(bool b, ref List? x, ref List? y) => ref (b ? ref x! : ref y)!; + ref List? M7(bool b, ref List? x, ref List? y) => ref (b ? ref x : ref y!)!; + ref List? M8(bool b, ref List? x, ref List? y) => ref (b ? ref x! : ref y!)!; + } + """; + CreateCompilation(source).VerifyDiagnostics( + // (5,92): warning CS8619: Nullability of reference types in value of type 'System.Collections.Generic.List?' doesn't match target type 'System.Collections.Generic.List?'. + // ref List? M1(bool b, ref List? x, ref List? y) => ref b ? ref x : ref y; + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "x").WithArguments("System.Collections.Generic.List?", "System.Collections.Generic.List?").WithLocation(5, 92), + // (7,92): warning CS8619: Nullability of reference types in value of type 'System.Collections.Generic.List?' doesn't match target type 'System.Collections.Generic.List?'. + // ref List? M3(bool b, ref List? x, ref List? y) => ref b ? ref x : ref y!; + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "x").WithArguments("System.Collections.Generic.List?", "System.Collections.Generic.List?").WithLocation(7, 92), + // (9,93): warning CS8619: Nullability of reference types in value of type 'System.Collections.Generic.List?' doesn't match target type 'System.Collections.Generic.List?'. + // ref List? M5(bool b, ref List? x, ref List? y) => ref (b ? ref x : ref y)!; + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "x").WithArguments("System.Collections.Generic.List?", "System.Collections.Generic.List?").WithLocation(9, 93), + // (11,93): warning CS8619: Nullability of reference types in value of type 'System.Collections.Generic.List?' doesn't match target type 'System.Collections.Generic.List?'. + // ref List? M7(bool b, ref List? x, ref List? y) => ref (b ? ref x : ref y!)!; + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "x").WithArguments("System.Collections.Generic.List?", "System.Collections.Generic.List?").WithLocation(11, 93)); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/73928")] + public void ConditionalOperator_Suppression_Ref_Nested_02() + { + var source = """ + #nullable enable + using System.Collections.Generic; + class C + { + ref List? M1(bool b, ref List? x, ref List? y) => ref b ? ref x : ref y; + ref List? M2(bool b, ref List? x, ref List? y) => ref b ? ref x! : ref y; + ref List? M3(bool b, ref List? x, ref List? y) => ref b ? ref x : ref y!; + ref List? M4(bool b, ref List? x, ref List? y) => ref b ? ref x! : ref y!; + ref List? M5(bool b, ref List? x, ref List? y) => ref (b ? ref x : ref y)!; + ref List? M6(bool b, ref List? x, ref List? y) => ref (b ? ref x! : ref y)!; + ref List? M7(bool b, ref List? x, ref List? y) => ref (b ? ref x : ref y!)!; + ref List? M8(bool b, ref List? x, ref List? y) => ref (b ? ref x! : ref y!)!; + } + """; + CreateCompilation(source).VerifyDiagnostics( + // (5,85): warning CS8619: Nullability of reference types in value of type 'System.Collections.Generic.List?' doesn't match target type 'System.Collections.Generic.List?'. + // ref List? M1(bool b, ref List? x, ref List? y) => ref b ? ref x : ref y; + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref x : ref y").WithArguments("System.Collections.Generic.List?", "System.Collections.Generic.List?").WithLocation(5, 85), + // (5,93): warning CS8619: Nullability of reference types in value of type 'System.Collections.Generic.List?' doesn't match target type 'System.Collections.Generic.List?'. + // ref List? M1(bool b, ref List? x, ref List? y) => ref b ? ref x : ref y; + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "x").WithArguments("System.Collections.Generic.List?", "System.Collections.Generic.List?").WithLocation(5, 93), + // (6,85): warning CS8619: Nullability of reference types in value of type 'System.Collections.Generic.List?' doesn't match target type 'System.Collections.Generic.List?'. + // ref List? M2(bool b, ref List? x, ref List? y) => ref b ? ref x! : ref y; + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref x! : ref y").WithArguments("System.Collections.Generic.List?", "System.Collections.Generic.List?").WithLocation(6, 85), + // (7,85): warning CS8619: Nullability of reference types in value of type 'System.Collections.Generic.List?' doesn't match target type 'System.Collections.Generic.List?'. + // ref List? M3(bool b, ref List? x, ref List? y) => ref b ? ref x : ref y!; + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref x : ref y!").WithArguments("System.Collections.Generic.List?", "System.Collections.Generic.List?").WithLocation(7, 85), + // (7,93): warning CS8619: Nullability of reference types in value of type 'System.Collections.Generic.List?' doesn't match target type 'System.Collections.Generic.List?'. + // ref List? M3(bool b, ref List? x, ref List? y) => ref b ? ref x : ref y!; + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "x").WithArguments("System.Collections.Generic.List?", "System.Collections.Generic.List?").WithLocation(7, 93), + // (8,85): warning CS8619: Nullability of reference types in value of type 'System.Collections.Generic.List?' doesn't match target type 'System.Collections.Generic.List?'. + // ref List? M4(bool b, ref List? x, ref List? y) => ref b ? ref x! : ref y!; + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref x! : ref y!").WithArguments("System.Collections.Generic.List?", "System.Collections.Generic.List?").WithLocation(8, 85), + // (9,94): warning CS8619: Nullability of reference types in value of type 'System.Collections.Generic.List?' doesn't match target type 'System.Collections.Generic.List?'. + // ref List? M5(bool b, ref List? x, ref List? y) => ref (b ? ref x : ref y)!; + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "x").WithArguments("System.Collections.Generic.List?", "System.Collections.Generic.List?").WithLocation(9, 94), + // (11,94): warning CS8619: Nullability of reference types in value of type 'System.Collections.Generic.List?' doesn't match target type 'System.Collections.Generic.List?'. + // ref List? M7(bool b, ref List? x, ref List? y) => ref (b ? ref x : ref y!)!; + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "x").WithArguments("System.Collections.Generic.List?", "System.Collections.Generic.List?").WithLocation(11, 94)); + } + [Fact, WorkItem(33664, "https://github.com/dotnet/roslyn/issues/33664")] public void ConditionalOperator_AssigningToRefConditional() { @@ -55212,15 +55525,15 @@ void M4(bool c, ref string x, ref string? y) }", options: WithNullableEnable(), references: new[] { ref0 }); comp.VerifyDiagnostics( - // (6,10): warning CS8619: Nullability of reference types in value of type 'string' doesn't match target type 'string?'. + // (6,26): warning CS8619: Nullability of reference types in value of type 'string?' doesn't match target type 'string'. // (c ? ref x : ref y) = null; // 1, 2 - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "c ? ref x : ref y").WithArguments("string", "string?").WithLocation(6, 10), + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "y").WithArguments("string?", "string").WithLocation(6, 26), // (6,31): warning CS8625: Cannot convert null literal to non-nullable reference type. // (c ? ref x : ref y) = null; // 1, 2 Diagnostic(ErrorCode.WRN_NullAsNonNullable, "null").WithLocation(6, 31), - // (10,10): warning CS8619: Nullability of reference types in value of type 'string?' doesn't match target type 'string'. + // (10,18): warning CS8619: Nullability of reference types in value of type 'string?' doesn't match target type 'string'. // (c ? ref y : ref x) = null; // 3, 4 - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "c ? ref y : ref x").WithArguments("string?", "string").WithLocation(10, 10), + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "y").WithArguments("string?", "string").WithLocation(10, 18), // (10,31): warning CS8625: Cannot convert null literal to non-nullable reference type. // (c ? ref y : ref x) = null; // 3, 4 Diagnostic(ErrorCode.WRN_NullAsNonNullable, "null").WithLocation(10, 31), @@ -90558,6 +90871,49 @@ static class Extensions comp.VerifyDiagnostics(); } + [Fact] + public void Foreach_NullableElementType_Suppression() + { + var source = """ + #nullable enable + class C + { + void M1(object?[] a) { foreach (object item in a) { } } + void M2(object[] a) { foreach (object item in a!) { } } + } + """; + CreateCompilation(source).VerifyDiagnostics( + // (4,44): warning CS8600: Converting null literal or possible null value to non-nullable type. + // void M1(object?[] a) { foreach (object item in a) { } } + Diagnostic(ErrorCode.WRN_ConvertingNullableToNonNullable, "item").WithLocation(4, 44)); + } + + [Fact] + public void Foreach_NullableElementType_Suppression_Ref() + { + var source = """ + #nullable enable + class RefList + { + public RefEnumerator GetEnumerator() => new RefEnumerator(); + public struct RefEnumerator + { + public ref object? Current => throw null!; + public bool MoveNext() => false; + } + } + class C + { + void M1(RefList refList) { foreach (ref object item in refList) { } } + void M2(RefList refList) { foreach (ref object item in refList!) { } } + } + """; + CreateCompilation(source).VerifyDiagnostics( + // (13,41): warning CS8619: Nullability of reference types in value of type 'object?' doesn't match target type 'object'. + // void M1(RefList refList) { foreach (ref object item in refList) { } } + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "ref object").WithArguments("object?", "object").WithLocation(13, 41)); + } + [Fact] public void TypeInference_01() { @@ -151490,21 +151846,21 @@ static void F4(bool b, I x4, I y4) // (15,25): warning CS8619: Nullability of reference types in value of type 'T' doesn't match target type 'T?'. // ref T? t2 = ref b ? ref x2 : ref y2; // 1 Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref x2 : ref y2").WithArguments("T", "T?").WithLocation(15, 25), - // (15,25): warning CS8619: Nullability of reference types in value of type 'T' doesn't match target type 'T?'. + // (15,42): warning CS8619: Nullability of reference types in value of type 'T?' doesn't match target type 'T'. // ref T? t2 = ref b ? ref x2 : ref y2; // 1 - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref x2 : ref y2").WithArguments("T", "T?").WithLocation(15, 25), - // (16,25): warning CS8619: Nullability of reference types in value of type 'T?' doesn't match target type 'T'. - // ref T? t3 = ref b ? ref y2 : ref x2; // 2 - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref y2 : ref x2").WithArguments("T?", "T").WithLocation(16, 25), + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "y2").WithArguments("T?", "T").WithLocation(15, 42), // (16,25): warning CS8619: Nullability of reference types in value of type 'T' doesn't match target type 'T?'. // ref T? t3 = ref b ? ref y2 : ref x2; // 2 Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref y2 : ref x2").WithArguments("T", "T?").WithLocation(16, 25), - // (29,28): warning CS8619: Nullability of reference types in value of type 'I' doesn't match target type 'I'. + // (16,33): warning CS8619: Nullability of reference types in value of type 'T?' doesn't match target type 'T'. + // ref T? t3 = ref b ? ref y2 : ref x2; // 2 + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "y2").WithArguments("T?", "T").WithLocation(16, 33), + // (29,36): warning CS8619: Nullability of reference types in value of type 'I' doesn't match target type 'I'. // ref I t2 = ref b ? ref x4 : ref y4; // 3 - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref x4 : ref y4").WithArguments("I", "I").WithLocation(29, 28), - // (30,28): warning CS8619: Nullability of reference types in value of type 'I' doesn't match target type 'I'. + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "x4").WithArguments("I", "I").WithLocation(29, 36), + // (30,45): warning CS8619: Nullability of reference types in value of type 'I' doesn't match target type 'I'. // ref I t3 = ref b ? ref y4 : ref x4; // 4 - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref y4 : ref x4").WithArguments("I", "I").WithLocation(30, 28)); + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "x4").WithArguments("I", "I").WithLocation(30, 45)); } [Fact]