From 3cce1059c0f529350b61271c51492413eb4046a6 Mon Sep 17 00:00:00 2001 From: Eugene Auduchinok Date: Thu, 22 Sep 2022 16:52:25 +0200 Subject: [PATCH 1/2] Use synthetic ranges when rewriting range expressions --- src/Compiler/Checking/CheckComputationExpressions.fs | 3 ++- src/Compiler/Checking/CheckExpressions.fs | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Compiler/Checking/CheckComputationExpressions.fs b/src/Compiler/Checking/CheckComputationExpressions.fs index 0f98af01961..c6dd6bbe9e4 100644 --- a/src/Compiler/Checking/CheckComputationExpressions.fs +++ b/src/Compiler/Checking/CheckComputationExpressions.fs @@ -81,7 +81,8 @@ let (|JoinRelation|_|) cenv env (expr: SynExpr) = | _ -> None -let elimFastIntegerForLoop (spFor, spTo, id, start, dir, finish, innerExpr, m) = +let elimFastIntegerForLoop (spFor, spTo, id, start, dir, finish, innerExpr, m: range) = + let m = m.MakeSynthetic() let pseudoEnumExpr = if dir then mkSynInfix m start ".." finish else mkSynTrifix m ".. .." start (SynExpr.Const (SynConst.Int32 -1, start.Range)) finish diff --git a/src/Compiler/Checking/CheckExpressions.fs b/src/Compiler/Checking/CheckExpressions.fs index 6aade43c55f..c7f4c522525 100644 --- a/src/Compiler/Checking/CheckExpressions.fs +++ b/src/Compiler/Checking/CheckExpressions.fs @@ -6097,10 +6097,12 @@ and RewriteRangeExpr synExpr = match synExpr with // a..b..c (parsed as (a..b)..c ) | SynExpr.IndexRange(Some (SynExpr.IndexRange(Some synExpr1, _, Some synStepExpr, _, _, _)), _, Some synExpr2, _m1, _m2, mWhole) -> + let mWhole = mWhole.MakeSynthetic() Some (mkSynTrifix mWhole ".. .." synExpr1 synStepExpr synExpr2) // a..b | SynExpr.IndexRange (Some synExpr1, mOperator, Some synExpr2, _m1, _m2, mWhole) -> let otherExpr = + let mWhole = mWhole.MakeSynthetic() match mkSynInfix mOperator synExpr1 ".." synExpr2 with | SynExpr.App (a, b, c, d, _) -> SynExpr.App (a, b, c, d, mWhole) | _ -> failwith "impossible" From 9c718f2c5f4ead604931d8247fb5f0ecd0b8d844 Mon Sep 17 00:00:00 2001 From: Don Syme Date: Mon, 17 Oct 2022 13:19:58 +0100 Subject: [PATCH 2/2] Update CheckComputationExpressions.fs --- src/Compiler/Checking/CheckComputationExpressions.fs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Compiler/Checking/CheckComputationExpressions.fs b/src/Compiler/Checking/CheckComputationExpressions.fs index c6dd6bbe9e4..db8d307381f 100644 --- a/src/Compiler/Checking/CheckComputationExpressions.fs +++ b/src/Compiler/Checking/CheckComputationExpressions.fs @@ -81,11 +81,11 @@ let (|JoinRelation|_|) cenv env (expr: SynExpr) = | _ -> None -let elimFastIntegerForLoop (spFor, spTo, id, start, dir, finish, innerExpr, m: range) = - let m = m.MakeSynthetic() +let elimFastIntegerForLoop (spFor, spTo, id, start: SynExpr, dir, finish: SynExpr, innerExpr, m: range) = + let mOp = (unionRanges start.Range finish.Range).MakeSynthetic() let pseudoEnumExpr = - if dir then mkSynInfix m start ".." finish - else mkSynTrifix m ".. .." start (SynExpr.Const (SynConst.Int32 -1, start.Range)) finish + if dir then mkSynInfix mOp start ".." finish + else mkSynTrifix mOp ".. .." start (SynExpr.Const (SynConst.Int32 -1, mOp)) finish SynExpr.ForEach (spFor, spTo, SeqExprOnly false, true, mkSynPatVar None id, pseudoEnumExpr, innerExpr, m) /// Check if a computation or sequence expression is syntactically free of 'yield' (though not yield!)