Skip to content

Commit df15c64

Browse files
authored
Don't update analyzed nullability for parameter conversions (#36881)
* Don't update analyzed nullability for param conversions * Fix test types
1 parent 08bdc66 commit df15c64

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,9 @@ private TypeWithState ResultType
204204
get => _visitResult.RValueType;
205205
}
206206

207-
private void SetResultType(BoundExpression expression, TypeWithState type)
207+
private void SetResultType(BoundExpression expression, TypeWithState type, bool updateAnalyzedNullability = true)
208208
{
209-
SetResult(expression, resultType: type, lvalueType: type.ToTypeWithAnnotations());
209+
SetResult(expression, resultType: type, lvalueType: type.ToTypeWithAnnotations(), updateAnalyzedNullability: updateAnalyzedNullability);
210210
}
211211

212212
/// <summary>
@@ -3188,7 +3188,7 @@ private void VisitArgumentConversionAndInboundAssignmentsAndPreConditions(
31883188

31893189
// If the parameter has annotations, we perform an additional check for nullable value types
31903190
CheckDisallowedNullAssignment(stateAfterConversion, parameterAnnotations, argumentNoConversion.Syntax.Location);
3191-
SetResultType(argumentNoConversion, stateAfterConversion);
3191+
SetResultType(argumentNoConversion, stateAfterConversion, updateAnalyzedNullability: false);
31923192
}
31933193
break;
31943194
case RefKind.Ref:

src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34457,9 +34457,9 @@ static void F7(IOut<object>? x7, IOut<object> y7)
3445734457
}
3445834458

3445934459
[Fact]
34460+
[WorkItem(35012, "https://github.com/dotnet/roslyn/issues/35012")]
3446034461
public void IdentityConversion_NullCoalescingOperator_02()
3446134462
{
34462-
// F1's types are incorrect. See https://github.com/dotnet/roslyn/issues/35012
3446334463
var source =
3446434464
@"interface IIn<in T> { }
3446534465
interface IOut<out T> { }
@@ -34482,8 +34482,8 @@ static T FOut<T>(IOut<T>? x)
3448234482
}
3448334483
static void F1(IIn<object>? x1, IIn<object?>? y1)
3448434484
{
34485-
FIn((x1 ?? y1)/*T:IIn<object?>?*/);
34486-
FIn((y1 ?? x1)/*T:IIn<object?>?*/);
34485+
FIn((x1 ?? y1)/*T:IIn<object!>?*/);
34486+
FIn((y1 ?? x1)/*T:IIn<object!>?*/);
3448734487
}
3448834488
static void F2(IOut<object>? x2, IOut<object?>? y2)
3448934489
{
@@ -34494,10 +34494,10 @@ static void F3(object? x3, object? y3)
3449434494
{
3449534495
FIn((FIn(x3) ?? FIn(y3))/*T:IIn<object?>?*/); // A
3449634496
if (x3 == null) return;
34497-
FIn((FIn(x3) ?? FIn(y3))/*T:IIn<object?>?*/); // B
34498-
FIn((FIn(y3) ?? FIn(x3))/*T:IIn<object?>?*/); // C
34497+
FIn((FIn(x3) ?? FIn(y3))/*T:IIn<object!>?*/); // B
34498+
FIn((FIn(y3) ?? FIn(x3))/*T:IIn<object!>?*/); // C
3449934499
if (y3 == null) return;
34500-
FIn((FIn(x3) ?? FIn(y3))/*T:IIn<object?>?*/); // D
34500+
FIn((FIn(x3) ?? FIn(y3))/*T:IIn<object!>?*/); // D
3450134501
}
3450234502
static void F4(object? x4, object? y4)
3450334503
{

0 commit comments

Comments
 (0)