Skip to content

Commit 0616707

Browse files
CopilotT-Gro
andcommitted
Add IsInstanceMember check to only transform instance members of structs
Co-authored-by: T-Gro <[email protected]>
1 parent b8e8f28 commit 0616707

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/Compiler/Checking/Expressions/CheckExpressions.fs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7331,12 +7331,14 @@ and TcObjectExpr (cenv: cenv) env tpenv (objTy, realObjTy, argopt, binds, extraI
73317331
let bodyFreeVars = freeInExpr CollectTyparsAndLocals body
73327332
unionFreeVars acc bodyFreeVars) emptyFreeVars
73337333

7334-
// Filter to only variables that are members of a struct type
7334+
// Filter to only instance members of struct types
7335+
// This identifies the problematic case: when an object expression inside a struct
7336+
// captures instance members, which would require capturing 'this' as a byref
73357337
let structMembers =
73367338
freeVars.FreeLocals
73377339
|> Zset.elements
73387340
|> List.filter (fun v ->
7339-
v.HasDeclaringEntity && isStructTyconRef v.DeclaringEntity)
7341+
v.IsInstanceMember && v.HasDeclaringEntity && isStructTyconRef v.DeclaringEntity)
73407342

73417343
if structMembers.IsEmpty then
73427344
[], Remap.Empty

0 commit comments

Comments
 (0)