Skip to content

Allow constrained. call and ldftn for static virtual interface methods in ILVerify - #132944

Merged
jkotas merged 2 commits into
dotnet:mainfrom
pkuyo:fix-ilverify-132820
Sep 4, 2026
Merged

Allow constrained. call and ldftn for static virtual interface methods in ILVerify#132944
jkotas merged 2 commits into
dotnet:mainfrom
pkuyo:fix-ilverify-132820

Conversation

@pkuyo

@pkuyo pkuyo commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Fixes #132820

ILVerify predates static virtual interface methods, so the IL Roslyn emits for T.M() (constrained. !!T followed by call) gets flagged with bogus Constrained and CallAbstract errors.

Consume the constrained. prefix on call when the target is a static virtual method on an interface, and check that the constrained type actually implements that interface (new ConstrainedTypeNoInterfaceImpl error).

Tests added to PrefixTests.il.

@github-actions github-actions Bot added the area-Tools-ILVerification Issues related to ilverify tool and IL verification in general label Aug 30, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@pkuyo pkuyo changed the title Allow constrained. call to static virtual interface methods Allow constrained. call and ldftn for static virtual interface methods in ILVerify Aug 31, 2026
@jkotas
jkotas requested a lite review from Copilot September 4, 2026 01:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The change is narrowly scoped, adds a targeted new verifier diagnostic with resources, and includes tests that cover both the accepted patterns and the new failure mode.

Pull request overview

This PR updates the CoreCLR ILVerify importer to recognize and validate the IL pattern used for static virtual interface method dispatch via a constrained type (e.g., constrained. !!T followed by call / ldftn), and introduces a dedicated verifier error when the constrained type cannot be proven to implement the target interface.

Changes:

  • Teach ILImporter.Verify to consume constrained. on call/ldftn targeting a static virtual interface method, instead of reporting Constrained / CallAbstract.
  • Add a new verifier error (ConstrainedTypeNoInterfaceImpl) and resource string for the new validation rule.
  • Extend PrefixTests.il with valid/invalid IL cases covering both call and ldftn scenarios.
File summaries
File Description
src/coreclr/tools/ILVerification/ILImporter.Verify.cs Consumes constrained. for static-virtual interface call/ldftn, relaxes CallAbstract only for that scenario, and validates interface implementation via CanCastTo.
src/coreclr/tools/ILVerification/VerifierError.cs Adds ConstrainedTypeNoInterfaceImpl to the verifier error enum.
src/coreclr/tools/ILVerification/Strings.resx Adds the localized message for ConstrainedTypeNoInterfaceImpl.
src/coreclr/tools/ILVerification.Tests/ILTests/PrefixTests.il Adds coverage for valid/invalid constrained static-virtual interface call and ldftn patterns.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 0
  • Review effort level: Lite

@jkotas jkotas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@jkotas

jkotas commented Sep 4, 2026

Copy link
Copy Markdown
Member

/ba-g known issue #132947 that has been fixed already

@jkotas
jkotas merged commit b1d01dc into dotnet:main Sep 4, 2026
127 of 129 checks passed
@pkuyo
pkuyo deleted the fix-ilverify-132820 branch September 5, 2026 02:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-Tools-ILVerification Issues related to ilverify tool and IL verification in general

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Calling static abstract method via type parameter generates code in C# that wont ILVerify

3 participants