Skip to content

Commit 673faf0

Browse files
committed
adjust assert
1 parent 1419b0f commit 673faf0

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9307,15 +9307,18 @@ private void TrackAnalyzedNullabilityThroughConversionGroup(TypeWithState result
93079307
Debug.Assert(conversionOpt.ConversionGroupOpt == conversionGroup);
93089308
// TODO2: here the visit result has reinferred nested nullability and we were throwing that away to use the conversion type from initial binding. why?
93099309
// it makes no sense for the visit result to be lacking information that the initial bound type actually has.
9310-
Debug.Assert(visitResult.LValueType.Type.Equals(conversionOpt.Type, TypeCompareKind.AllNullableIgnoreOptions));
9311-
//visitResult = withType(visitResult, conversionOpt.Type);
9310+
// TODO2: what does it mean for these types to differ? Why is it correct to copy over the top-level nullability when the types have differences beyond nullability?
9311+
if (!visitResult.LValueType.Type.Equals(conversionOpt.Type, TypeCompareKind.AllNullableIgnoreOptions))
9312+
{
9313+
visitResult = withType(visitResult, conversionOpt.Type);
9314+
}
93129315
SetAnalyzedNullability(conversionOpt, visitResult);
93139316
conversionOpt = conversionOpt.Operand as BoundConversion;
93149317
}
93159318

9316-
//static VisitResult withType(VisitResult visitResult, TypeSymbol newType) =>
9317-
// new VisitResult(TypeWithState.Create(newType, visitResult.RValueType.State),
9318-
// TypeWithAnnotations.Create(newType, visitResult.LValueType.NullableAnnotation));
9319+
static VisitResult withType(VisitResult visitResult, TypeSymbol newType) =>
9320+
new VisitResult(TypeWithState.Create(newType, visitResult.RValueType.State),
9321+
TypeWithAnnotations.Create(newType, visitResult.LValueType.NullableAnnotation));
93199322
}
93209323

93219324
/// <summary>

src/Compilers/CSharp/Test/Symbol/Symbols/Source/NullablePublicAPITests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5435,7 +5435,7 @@ public void Repro_WithSwitchExpr()
54355435
#nullable enable
54365436
54375437
var b = false;
5438-
var arr = b switch { true => ["1", null], false => new[] { "2", null } };
5438+
var arr = b switch { true => ["1"], false => new[] { "2" } };
54395439
""";
54405440

54415441
var comp = CreateCompilation(source);

0 commit comments

Comments
 (0)