Skip to content

Commit

Permalink
Use synthetic ranges when rewriting range expressions (#13958)
Browse files Browse the repository at this point in the history
Co-authored-by: Don Syme <[email protected]>
Co-authored-by: Tomas Grosup <[email protected]>
Co-authored-by: Don Syme <[email protected]>
Co-authored-by: Vlad Zarytovskii <[email protected]>
  • Loading branch information
5 people authored Oct 21, 2022
1 parent 2178ab3 commit 7d842a5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/Compiler/Checking/CheckComputationExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,11 @@ let (|JoinRelation|_|) cenv env (expr: SynExpr) =

| _ -> None

let elimFastIntegerForLoop (spFor, spTo, id, start, dir, finish, innerExpr, m) =
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!)
Expand Down
2 changes: 2 additions & 0 deletions src/Compiler/Checking/CheckExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6125,10 +6125,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"
Expand Down

0 comments on commit 7d842a5

Please sign in to comment.