Skip to content

Commit 4cc5737

Browse files
PhysShellclaude
andcommitted
feat(s2-step11): green — positive runtime-FAMILY predicate in bind (L1)
RuntimeIncompatible now positively establishes an incompatible runtime FAMILY as well as a newer same-family contract: it reads the selected probe runtime's core family from the compilation (System.Object's containing assembly — System.Private.CoreLib for CoreCLR) and refuses WRAPPER_RUNTIME_UNSUPPORTED when the wrapper references mscorlib under a CoreCLR probe (or System.Private.CoreLib under a non-CoreCLR probe), a System.Runtime / System.Private.CoreLib contract at a version strictly newer than the runtime supplies, or carries a TargetFrameworkAttribute that positively declares an incompatible family. A netstandard reference is never a reason to reject. The check runs on BOTH the Symbol==null path and the cleanly-bound path (a net48 wrapper retargets onto the net8 refs and binds), so it is refused before probing. Argument-conversion failures, ambiguous handler groups, source-defined targets and multiple assemblies remain CALLSITE_BINDING; a wrong frozen shape remains WRAPPER_BINDING. Tier B 65/65. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JxKjqdGEFzq4UzZupw379G
1 parent 5f0984a commit 4cc5737

1 file changed

Lines changed: 43 additions & 10 deletions

File tree

  • frontend/roslyn/OwnSharp.WeakTargetProbe

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

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,12 @@ public static int Run(string[] args)
203203
// overload, no ref/optional/params/modopt) — any mismatch is WRAPPER_BINDING.
204204
var terr = TargetBinding.Validate(sym.ContainingAssembly, target);
205205
if (terr is not null) return Refuse("WRAPPER_BINDING", $"{e.Fid}: {terr}");
206+
// even a CLEANLY BOUND wrapper may target an incompatible runtime family (e.g. a
207+
// .NET Framework mscorlib wrapper whose types retarget onto the net8 refs) — the
208+
// positive runtime-family predicate refuses it before probing (L1).
209+
if (RuntimeIncompatible(comp, sym.ContainingAssembly))
210+
return Refuse("WRAPPER_RUNTIME_UNSUPPORTED",
211+
$"{e.Fid}: the wrapper targets a runtime family/version incompatible with the probe runtime");
206212
derivedOrdinal = slot.Ordinal;
207213
asmName = sym.ContainingAssembly.Name;
208214
mvid = ReadMvid(path);
@@ -350,24 +356,51 @@ private static int RefuseUnbound(string fid, SymbolInfo si, CSharpCompilation co
350356
return Refuse("CALLSITE_BINDING", $"{fid}: the invocation does not bind to a single wrapper symbol");
351357
}
352358

353-
// The POSITIVE runtime-incompatibility predicate (K3): the wrapper assembly references a core
354-
// framework assembly at a version STRICTLY NEWER than the one the selected probe runtime provides
355-
// to this compilation. This is a deterministic metadata comparison, not an inference from a
356-
// failed overload — a shape-correct wrapper that merely fails to bind for another reason is NOT
357-
// runtime-incompatible.
358-
private static readonly HashSet<string> CoreFramework = new(StringComparer.OrdinalIgnoreCase)
359-
{ "System.Runtime", "System.Private.CoreLib", "netstandard", "mscorlib" };
359+
// The POSITIVE runtime-compatibility predicate (K3 / L1): a deterministic metadata comparison,
360+
// never an inference from a failed overload. It positively establishes BOTH an incompatible
361+
// runtime FAMILY (a .NET-Framework `mscorlib` wrapper under a CoreCLR probe, or a CoreCLR
362+
// `System.Private.CoreLib` wrapper under a non-CoreCLR probe) AND a newer SAME-family runtime
363+
// contract (a core contract at a version strictly newer than the selected runtime supplies), plus
364+
// a TargetFrameworkAttribute that positively declares an incompatible family. A netstandard
365+
// reference is NEVER a reason to reject (netstandard is a compatibility contract, not a family).
366+
private static readonly HashSet<string> SameFamilyContract = new(StringComparer.OrdinalIgnoreCase)
367+
{ "System.Runtime", "System.Private.CoreLib" };
360368

361369
private static bool RuntimeIncompatible(CSharpCompilation comp, IAssemblySymbol wrapperAsm)
362370
{
363-
var compCore = comp.GetSpecialType(SpecialType.System_Object).ContainingAssembly.Identity.Version;
371+
var coreAsm = comp.GetSpecialType(SpecialType.System_Object).ContainingAssembly;
372+
var runtimeVersion = coreAsm.Identity.Version;
373+
var runtimeIsCoreClr = string.Equals(coreAsm.Name, "System.Private.CoreLib",
374+
StringComparison.OrdinalIgnoreCase);
364375
foreach (var mod in wrapperAsm.Modules)
365376
foreach (var r in mod.ReferencedAssemblies)
366-
if (CoreFramework.Contains(r.Name) && r.Version > compCore)
367-
return true;
377+
{
378+
if (string.Equals(r.Name, "mscorlib", StringComparison.OrdinalIgnoreCase)
379+
&& runtimeIsCoreClr)
380+
return true; // .NET Framework wrapper under a CoreCLR probe
381+
if (string.Equals(r.Name, "System.Private.CoreLib", StringComparison.OrdinalIgnoreCase)
382+
&& !runtimeIsCoreClr)
383+
return true; // CoreCLR wrapper under a non-CoreCLR probe
384+
if (SameFamilyContract.Contains(r.Name) && r.Version > runtimeVersion)
385+
return true; // a same-family core contract strictly newer than the runtime
386+
}
387+
foreach (var attr in wrapperAsm.GetAttributes())
388+
if (attr.AttributeClass?.ToDisplayString()
389+
== "System.Runtime.Versioning.TargetFrameworkAttribute"
390+
&& attr.ConstructorArguments.Length > 0
391+
&& attr.ConstructorArguments[0].Value is string moniker
392+
&& MonikerFamilyIncompatible(moniker, runtimeIsCoreClr))
393+
return true;
368394
return false;
369395
}
370396

397+
private static bool MonikerFamilyIncompatible(string moniker, bool runtimeIsCoreClr)
398+
{
399+
var isFramework = moniker.StartsWith(".NETFramework", StringComparison.OrdinalIgnoreCase);
400+
var isCoreApp = moniker.StartsWith(".NETCoreApp", StringComparison.OrdinalIgnoreCase);
401+
return (runtimeIsCoreClr && isFramework) || (!runtimeIsCoreClr && isCoreApp);
402+
}
403+
371404
private static int Refuse(string category, string message)
372405
{
373406
Console.Error.WriteLine($"{category}: {message}");

0 commit comments

Comments
 (0)