Repository navigation
Conversation
The direct-delegate recognizer removes side-effect-free let bindings from the delegate body to find the forwarded call. A leading argument of that call becomes the delegate Target, which is evaluated at the construction site. When that argument used a removed binding, for example a closure over a local function of the delegate body, code generation reported FS0971 "Undefined value". matchForwarding now rejects a leading argument that uses a removed binding. The delegate then stays a closure. Fixes dotnet#21032
This branch has not been deployed
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.
Fixes #21032
Description
The compiler reports FS0971 "Undefined value" for this code in Release builds with F# 11:
The direct-delegate recognizer (
DirectDelegateConstruction, #19993) removes side-effect-freeletbindings from the delegate body to find the forwarded call. Here, it findscall (closure)and usesclosureas the delegateTarget, which is evaluated at the construction site. The closure usesconv, but the construction site does not bindconv, so code generation reports FS0971.Fix
matchForwardingnow rejects a leading argument that uses a value that the recognizer removed. The delegate then stays a closure. The optimizer and IlxGen both use this function, so they make the same decision.Tests
Issue 21032 - receiver capturing a local of the delegate body compiles (preview)inEmittedIL/DirectDelegates/DirectDelegates.fs. Without the fix, its source fails with FS0971.DirectDelegatestests pass in Release on net11.0 and net472. No IL baseline changed.Checklist
🤖 Generated with Claude Code