From e9ff75057b169862d1a884e49aa1fd215f5b021e Mon Sep 17 00:00:00 2001 From: Rich Lander Date: Wed, 17 Jun 2026 23:26:58 -0700 Subject: [PATCH] compile-check: import internal members so internal-overload calls aren't false defects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The compile-check shell compiles each decompiled body against the runtime assemblies as an external assembly, so it cannot access their internal members. When a body legitimately calls an internal overload of the target assembly (e.g. the internal Span(ref T, int) ctor that Array.Fill/Span code uses), Roslyn never sees the intended overload and mis-binds to a public sibling, reporting a misleading CS1615/CS1620 (wrong ref/out keyword) — a false 'claimed good but isn't' signal even though the decompiled keyword is correct. Set MetadataImportOptions.Internal so Roslyn imports those members; it then recognizes the intended-but-inaccessible overload and reports CS0122 instead, which is already filtered as visibility noise. Verified against the generic-instance ref-kind work: four spurious CS1615 (Array.Fill/Sort/ UnsafeArrayAsSpan, String.JoinCore) drop to zero with no real defects hidden. Co-Authored-By: Claude Opus 4.8 (1M context) --- tools/DecompilerHarness/CompileChecker.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tools/DecompilerHarness/CompileChecker.cs b/tools/DecompilerHarness/CompileChecker.cs index 28bba238..912775d4 100644 --- a/tools/DecompilerHarness/CompileChecker.cs +++ b/tools/DecompilerHarness/CompileChecker.cs @@ -65,7 +65,17 @@ public static int Run(IReadOnlyList assemblies, int cap, int maxExamples var compileOptions = new CSharpCompilationOptions( OutputKind.DynamicallyLinkedLibrary, allowUnsafe: true, nullableContextOptions: NullableContextOptions.Disable) - .WithSpecificDiagnosticOptions(new Dictionary()); + .WithSpecificDiagnosticOptions(new Dictionary()) + // Import internal members of the referenced runtime assemblies. When a + // decompiled body legitimately calls an INTERNAL overload of the target + // assembly (e.g. the internal `Span(ref T, int)` ctor), the external + // shell cannot access it; without the internal members imported, Roslyn + // never sees the intended overload and mis-binds to a public sibling, + // reporting a misleading CS1615/CS1620 (wrong ref/out keyword). Imported, + // it recognizes the intended-but-inaccessible member and reports CS0122 + // instead — already filtered as visibility noise. The recovered keyword + // is correct; the diagnostic was an artifact of the external shell. + .WithMetadataImportOptions(MetadataImportOptions.Internal); int total = 0, fullTotal = 0, partialTotal = 0; int fullMalformed = 0, partialMalformed = 0;