Skip to content

Commit 6af3069

Browse files
authored
fix tupleget simplify for value tuple (#321)
1 parent c803f61 commit 6af3069

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/ProvidedTypes.fs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8423,12 +8423,26 @@ namespace ProviderImplementation.ProvidedTypes
84238423

84248424
// convert TupleGet to the chain of PropertyGet calls (only for generated types)
84258425
| TupleGet(e, i) when isGenerated ->
8426-
let rec mkGet ty i (e: Expr) =
8427-
let pi, restOpt = Reflection.FSharpValue.PreComputeTuplePropertyInfo(ty, i)
8428-
let propGet = Expr.PropertyGetUnchecked(e, pi)
8429-
match restOpt with
8430-
| None -> propGet
8431-
| Some (restTy, restI) -> mkGet restTy restI propGet
8426+
let rec mkGet (ty : Type) i (e: Expr) =
8427+
if ty.IsValueType then
8428+
let get index =
8429+
let fields = ty.GetFields() |> Array.sortBy (fun fi -> fi.Name)
8430+
if index >= fields.Length then
8431+
invalidArg "index" (sprintf "The tuple index '%d' was out of range for tuple type %s" index ty.Name)
8432+
fields.[index]
8433+
let tupleEncField = 7
8434+
let fget = Expr.FieldGetUnchecked(e, get i)
8435+
if i < tupleEncField then
8436+
fget
8437+
else
8438+
let etys = ty.GetGenericArguments()
8439+
mkGet etys.[tupleEncField] (i - tupleEncField) fget
8440+
else
8441+
let pi, restOpt = Reflection.FSharpValue.PreComputeTuplePropertyInfo(ty, i)
8442+
let propGet = Expr.PropertyGetUnchecked(e, pi)
8443+
match restOpt with
8444+
| None -> propGet
8445+
| Some (restTy, restI) -> mkGet restTy restI propGet
84328446
simplifyExpr (mkGet e.Type i (simplifyExpr e))
84338447
#endif
84348448

0 commit comments

Comments
 (0)