Skip to content

compile-check: import internal members to avoid false ref/out defects#608

Merged
richlander merged 1 commit into
mainfrom
feature/compile-check-import-internals
Jun 18, 2026
Merged

compile-check: import internal members to avoid false ref/out defects#608
richlander merged 1 commit into
mainfrom
feature/compile-check-import-internals

Conversation

@richlander

Copy link
Copy Markdown
Owner

Problem

--compile-check compiles each decompiled body in a synthetic shell assembly against the runtime assemblies. As an external assembly, it cannot access their internal members. So when a decompiled body legitimately calls an internal overload of the target assembly — e.g. the internal Span<T>(ref T reference, int length) constructor that Array.Fill/Span code 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 ref is 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.Internal on 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 ref arguments 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

…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>
@richlander richlander merged commit ca979da into main Jun 18, 2026
5 checks passed
@richlander richlander deleted the feature/compile-check-import-internals branch June 18, 2026 06:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant