Skip to content

Commit 87f1ac3

Browse files
committed
Fix some issues discovered when running nullability inference on ILSpy.
1 parent 8163e53 commit 87f1ac3

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

NullabilityInference/EdgeBuildingOperationVisitor.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1361,7 +1361,7 @@ private void CreateConversionEdge(TypeWithNode input, TypeWithNode target, Conve
13611361
if (elementConv.IsNullable)
13621362
throw new InvalidOperationException("Nullable unwrap failed");
13631363
CreateConversionEdge(input, target, elementConv, label);
1364-
} else if (conv.IsNumeric || conv.IsConstantExpression || conv.IsEnumeration) {
1364+
} else if (conv.IsNumeric || conv.IsConstantExpression || conv.IsEnumeration || conv.IsIntPtr) {
13651365
// OK, no edge required
13661366
Debug.Assert(target.Node.NullType == NullType.Oblivious);
13671367
} else if (conv.IsThrow) {
@@ -1789,5 +1789,16 @@ public override TypeWithNode VisitConstantPattern(IConstantPatternOperation oper
17891789
{
17901790
return typeSystem.GetObliviousType(operation.Type);
17911791
}
1792+
1793+
public override TypeWithNode VisitAddressOf(IAddressOfOperation operation, EdgeBuildingContext argument)
1794+
{
1795+
Visit(operation.Reference, EdgeBuildingContext.LValue);
1796+
return typeSystem.GetObliviousType(operation.Type);
1797+
}
1798+
1799+
public override TypeWithNode VisitSizeOf(ISizeOfOperation operation, EdgeBuildingContext argument)
1800+
{
1801+
return typeSystem.GetObliviousType(operation.Type);
1802+
}
17921803
}
17931804
}

NullabilityInference/NullabilityNode.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ public NullabilityNode ReplacedWith {
8989
/// </summary>
9090
internal void ReplaceWith(NullabilityNode other)
9191
{
92+
if (this == other) {
93+
return;
94+
}
9295
if (this.replacement != null) {
9396
this.replacement.ReplaceWith(other);
9497
return;
@@ -114,8 +117,7 @@ public SpecialNullabilityNode(NullType nullType)
114117

115118
public override Location? Location => null;
116119

117-
public override string Name => NullType switch
118-
{
120+
public override string Name => NullType switch {
119121
NullType.Nullable => "<nullable>",
120122
NullType.NonNull => "<nonnull>",
121123
NullType.Oblivious => "<oblivious>",
@@ -157,7 +159,7 @@ internal sealed class HelperNullabilityNode : NullabilityNode
157159
private readonly long id = Interlocked.Increment(ref nextId);
158160

159161
public override Location? Location => null;
160-
162+
161163
private string symbolName = "helper";
162164

163165
public override string Name => $"<{symbolName}#{id}>";

0 commit comments

Comments
 (0)