You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/fsharp/tc.fs
+19-7Lines changed: 19 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -3123,18 +3123,30 @@ let AnalyzeArbitraryExprAsEnumerable cenv (env: TcEnv) localAlloc m exprty expr
3123
3123
else
3124
3124
enumElemTy
3125
3125
3126
-
let enumeratorVar,enumeratorExpr =
3127
-
if isStructTy cenv.g retTypeOfGetEnumerator then
3126
+
let isEnumeratorTypeStruct = isStructTy cenv.g retTypeOfGetEnumerator
3127
+
let originalRetTypeOfGetEnumerator = retTypeOfGetEnumerator
3128
+
3129
+
let (enumeratorVar,enumeratorExpr), retTypeOfGetEnumerator =
3130
+
if isEnumeratorTypeStruct then
3128
3131
if localAlloc then
3129
-
Tastops.mkMutableCompGenLocal m "enumerator" retTypeOfGetEnumerator
3132
+
Tastops.mkMutableCompGenLocal m "enumerator" retTypeOfGetEnumerator, retTypeOfGetEnumerator
3130
3133
else
3131
-
let v,e = Tastops.mkMutableCompGenLocal m "enumerator" (mkRefCellTy cenv.g retTypeOfGetEnumerator)
3132
-
v,mkRefCellGet cenv.g m retTypeOfGetEnumerator e
3134
+
let refCellTyForRetTypeOfGetEnumerator = mkRefCellTy cenv.g retTypeOfGetEnumerator
3135
+
let v,e = Tastops.mkMutableCompGenLocal m "enumerator" refCellTyForRetTypeOfGetEnumerator
3136
+
(v, mkRefCellGet cenv.g m retTypeOfGetEnumerator e), refCellTyForRetTypeOfGetEnumerator
3133
3137
3134
3138
else
3135
-
Tastops.mkCompGenLocal m "enumerator" retTypeOfGetEnumerator
3139
+
Tastops.mkCompGenLocal m "enumerator" retTypeOfGetEnumerator, retTypeOfGetEnumerator
3136
3140
3137
-
let getEnumExpr ,getEnumTy = BuildPossiblyConditionalMethodCall cenv env PossiblyMutates m false getEnumerator_minfo NormalValUse getEnumerator_minst [exprToSearchForGetEnumeratorAndItem] []
3141
+
let getEnumExpr, getEnumTy =
3142
+
let (getEnumExpr, getEnumTy) as res = BuildPossiblyConditionalMethodCall cenv env PossiblyMutates m false getEnumerator_minfo NormalValUse getEnumerator_minst [exprToSearchForGetEnumeratorAndItem] []
3143
+
if not isEnumeratorTypeStruct || localAlloc then res
3144
+
else
3145
+
// wrap enumerators that are represented as mutable structs into ref cells
3146
+
let getEnumExpr = mkRefCell cenv.g m originalRetTypeOfGetEnumerator getEnumExpr
3147
+
let getEnumTy = mkRefCellTy cenv.g getEnumTy
3148
+
getEnumExpr, getEnumTy
3149
+
3138
3150
let guardExpr ,guardTy = BuildPossiblyConditionalMethodCall cenv env DefinitelyMutates m false moveNext_minfo NormalValUse moveNext_minst [enumeratorExpr] []
3139
3151
let currentExpr,currentTy = BuildPossiblyConditionalMethodCall cenv env DefinitelyMutates m true get_Current_minfo NormalValUse get_Current_minst [enumeratorExpr] []
3140
3152
let betterCurrentExpr = mkCoerceExpr(currentExpr,enumElemTy,currentExpr.Range,currentTy)