compile-check: import internal members to avoid false ref/out defects#608
Merged
Merged
Conversation
…n't false defects 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<T>(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) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
--compile-checkcompiles each decompiled body in a synthetic shell assembly against the runtime assemblies. As an external assembly, it cannot access theirinternalmembers. So when a decompiled body legitimately calls an internal overload of the target assembly — e.g. the internalSpan<T>(ref T reference, int length)constructor thatArray.Fill/Spancode uses — Roslyn never sees the intended overload, mis-binds to a public sibling (Span(void*, int)), and reports a misleading CS1615 ("argument may not be passed with the 'ref' keyword").The decompiled
refis correct (it matches the real corelib source); the diagnostic is an artifact of the external shell. These show up as false "claimed-good-but-isn't" defects.Fix
Set
MetadataImportOptions.Internalon the check compilation. Roslyn then imports the internal members, recognizes the intended-but-inaccessible overload as the best match, and reports CS0122 (inaccessible) instead — which is already in the binding-visibility noise filter. The genuine ref/out defect signal on public APIs is unaffected (still CS1615/CS1620).Validation
Against the generic-instance ref-kind recovery work (which makes these
refarguments appear), the four spurious CS1615 —Array.Fill,Array.Sort,Array.UnsafeArrayAsSpan,String.JoinCore— drop to zero, with no real defects hidden (confirmed via--diff-defects:REGRESSED: (none)). Harness-only change.🤖 Generated with Claude Code