-
Notifications
You must be signed in to change notification settings - Fork 845
Bugfix :: Object expressions in struct types generating invalid IL with byref fields #19070
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+298
−2
Conversation
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
…ef fields Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix invalid IL generation with byref fields in structs
Fix object expressions in struct types generating invalid IL with byref fields
Nov 11, 2025
Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
…ementations Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
…ar early guards Moved transformation logic from CheckExpressions.fs to CheckExpressionsOps.fs as requested. Added clear early guard conditions and comprehensive documentation. The transformation now has explicit early exits for: - Interface-only implementations (isInterfaceTy check) - Empty method bodies - No struct members captured This makes the code architecture clearer about when the new code executes. Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
Removed the overly complex generic type annotation for overridesAndVirts parameter that was causing type mismatch errors. F# can now properly infer the type from usage. Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
The transformation is causing false positives - it's being applied to object expressions in non-struct contexts, leading to byref type errors in files like ServiceParamInfoLocations.fs. Root cause: The check for `v.IsInstanceMember && isStructTyconRef v.DeclaringEntity` is too broad - it matches any struct instance member that appears as a free variable, even when the object expression is not inside a struct instance member method. Need to add context awareness to only transform when we're truly inside a struct instance member context, not just when we happen to reference any struct member. Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
Copilot
AI
changed the title
Fix object expressions in struct types generating invalid IL with byref fields
[WIP] Fix object expressions in struct types generating invalid IL with byref fields
Dec 31, 2025
Following reviewer's suggestion, the transformation now uses env.eFamilyType to detect when we're actually inside a struct instance member method, and checks that baseValOpt's type matches the enclosing struct. This fixes false positives by ensuring we only transform when: 1. Not a pure interface implementation (not isInterfaceTy) 2. Inside a struct instance member (env.eFamilyType is a struct tyconRef) 3. baseVal is being captured (baseValOpt is Some) 4. baseVal's type matches the enclosing struct (tyconRefEq check) This prevents transformation in module functions or class methods that happen to reference struct members, which was causing build failures. Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
Member
|
/run fantomas |
Contributor
🔧 CLI Command Report
✅ Patch applied: |
Member
Added release note entry to FSharp.Compiler.Service/11.0.0.md documenting the fix for object expressions in struct types generating invalid IL with byref fields (Issue #19068, PR #19070). The entry describes the runtime crash (TypeLoadException) that was fixed. Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
auto-merge was automatically disabled
January 19, 2026 12:36
Head branch was pushed to by a user without write access
Contributor
Author
abonie
approved these changes
Jan 20, 2026
This was referenced Jan 20, 2026
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
NO_RELEASE_NOTES
Label for pull requests which signals, that user opted-out of providing release notes
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.
Investigation: Object expressions in struct types generate invalid IL with byref fields
Problem
When object expressions inside struct member methods capture struct constructor parameters or fields, the compiler generates illegal
byref<Struct>fields in closure classes, causingTypeLoadExceptionat runtime.Relates to #19068
This pull request was created as a result of the following prompt from Copilot chat.
Release Notes
Release notes have been added to
docs/release-notes/.FSharp.Compiler.Service/11.0.0.mddocumenting this fix.💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.