Skip to content

Commit 3c98df2

Browse files
PhysShellclaude
andcommitted
extractor: follow (this as I).M() self-calls in the #278 teardown closure
A teardown context that calls THIS object's own implementation of an interface member through a cast -- (this as I).M(), ((I)this).M(), (this as I)?.M() -- bound to the interface method, so the same-class edge of the closure never matched and a `-=` in that implementation read as never run (MAUI iOS Shell renderers: Dispose(bool) -> (this as IDisconnectable).Disconnect()). The edge now adds cls.FindImplementationForInterfaceMember(im) when it is declared in this class and the call is not parameter-guarded; everything else keeps today's warning. No OwnIR, core, Rust or message change. C01-PRECISION-1 (research spike, not for merge): docs/evidence/c01-precision-2026-10/. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 978161c commit 3c98df2

1 file changed

Lines changed: 47 additions & 2 deletions

File tree

‎frontend/roslyn/OwnSharp.Extractor/Program.cs‎

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,8 +1096,9 @@ void Add(IMethodSymbol? m)
10961096
}
10971097

10981098
// intra-class closure: a method/local function a teardown context provably
1099-
// calls (bare or `this.`-qualified, RESOLVED to a symbol of this class) is
1100-
// itself a teardown context. Unresolved calls extend nothing — the worst
1099+
// calls (bare or `this.`-qualified, RESOLVED to a symbol of this class, or
1100+
// this class's own implementation reached through `(this as I).M()` — see
1101+
// SelfInterfaceImplementation) is itself a teardown context. Unresolved calls extend nothing — the worst
11011102
// case stays "keeps today's honest warning".
11021103
while (work.Count > 0)
11031104
{
@@ -1116,6 +1117,11 @@ void Add(IMethodSymbol? m)
11161117
continue;
11171118
foreach (var inv in DirectBodyNodes(body).OfType<InvocationExpressionSyntax>())
11181119
{
1120+
if (SelfInterfaceImplementation(inv, model, clsSymbol) is { } impl)
1121+
{
1122+
Add(impl);
1123+
continue;
1124+
}
11191125
if (inv.Expression is not (IdentifierNameSyntax
11201126
or MemberAccessExpressionSyntax { Expression: ThisExpressionSyntax }))
11211127
continue;
@@ -1131,6 +1137,45 @@ void Add(IMethodSymbol? m)
11311137
return teardown;
11321138
}
11331139

1140+
// C01-PRECISION-1: the closure edge for a call to THIS object's own implementation of an interface member
1141+
// through a cast — `(this as I).M()`, `((I)this).M()`, `(this as I)?.M()` (mined: the MAUI iOS Shell
1142+
// renderers' `Dispose(bool)` -> `(this as IDisconnectable).Disconnect()`, whose `-=` read as never run).
1143+
// Such a call binds to the INTERFACE method, so the same-class check of the closure never matched it, yet C#
1144+
// dispatch on `this` reaches exactly `cls.FindImplementationForInterfaceMember(im)`. Credited only when that
1145+
// implementation is declared in THIS class and the call is not under a parameter guard (stricter than the
1146+
// bare `M()` edge); a base-class implementation, a cast of another object, a different member, or an
1147+
// unresolved call returns null and keeps today's warning. Symbol-exact: no interface or method name is read.
1148+
static IMethodSymbol? SelfInterfaceImplementation(
1149+
InvocationExpressionSyntax inv, SemanticModel model, INamedTypeSymbol? cls)
1150+
{
1151+
if (cls is null)
1152+
return null;
1153+
var receiver = inv.Expression switch
1154+
{
1155+
MemberAccessExpressionSyntax ma => ma.Expression,
1156+
MemberBindingExpressionSyntax when inv.Parent is ConditionalAccessExpressionSyntax ca
1157+
&& ReferenceEquals(ca.WhenNotNull, inv) => ca.Expression,
1158+
_ => null,
1159+
};
1160+
while (receiver is ParenthesizedExpressionSyntax p)
1161+
receiver = p.Expression;
1162+
var operand = receiver switch
1163+
{
1164+
BinaryExpressionSyntax b when b.IsKind(SyntaxKind.AsExpression) => b.Left,
1165+
CastExpressionSyntax c => c.Expression,
1166+
_ => null,
1167+
};
1168+
while (operand is ParenthesizedExpressionSyntax p)
1169+
operand = p.Expression;
1170+
if (operand is not ThisExpressionSyntax
1171+
|| model.GetSymbolInfo(inv).Symbol is not IMethodSymbol { ContainingType.TypeKind: TypeKind.Interface } im
1172+
|| cls.FindImplementationForInterfaceMember(im) is not IMethodSymbol impl
1173+
|| !SymbolEqualityComparer.Default.Equals(impl.ContainingType, cls)
1174+
|| IsParamGuardedRelease(inv, model))
1175+
return null;
1176+
return impl;
1177+
}
1178+
11341179
// Does this `-=` sit in a PROVEN teardown context of `cls`? Walks the lexical
11351180
// ancestors to the nearest callable and asks whether that callable provably runs
11361181
// at teardown. A ctor, an accessor (a rebinding setter is the #163 gap, not a

0 commit comments

Comments
 (0)