Skip to content

Commit

Permalink
TreeOps: fix statement start for rewritten lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Sep 29, 2021
1 parent 4e4e227 commit d33c573
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ object TreeOps {
}
// special handling for rewritten apply(x => { b }) to a { x => b }
case Term.Apply(_, List(f: Term.Function))
if f.tokens.lastOption // see if closing brace was moved
.exists(x => x.is[Token.RightBrace] && replacedWith(x).ne(x)) =>
if subtree.tokens.lastOption // see if closing paren was moved
.exists(x => x.is[Token.RightParen] && replacedWith(x).ne(x)) =>
addAll(Seq(f))
case t => // Nothing
addAll(extractStatementsIfAny(t))
Expand Down
14 changes: 5 additions & 9 deletions scalafmt-tests/src/test/resources/scala3/OptionalBraces.stat
Original file line number Diff line number Diff line change
Expand Up @@ -1987,12 +1987,8 @@ object x:
v + 1
})
>>>
Idempotency violated
object x:
- val y = List(1).map(v =>
+ val y = List(1).map(
+ v =>
println(v)
- v + 1
- )
+ v + 1)
object x:
val y = List(1).map(v =>
println(v)
v + 1
)
Original file line number Diff line number Diff line change
Expand Up @@ -1936,12 +1936,8 @@ object x:
v + 1
})
>>>
Idempotency violated
object x:
- val y = List(1).map(v =>
+ val y = List(1).map(
+ v =>
println(v)
- v + 1
- )
+ v + 1)
object x:
val y = List(1).map(v =>
println(v)
v + 1
)
Original file line number Diff line number Diff line change
Expand Up @@ -2028,12 +2028,8 @@ object x:
v + 1
})
>>>
Idempotency violated
object x:
- val y = List(1).map(v =>
+ val y = List(1).map(
+ v =>
println(v)
- v + 1
- )
+ v + 1)
object x:
val y = List(1).map(v =>
println(v)
v + 1
)
Original file line number Diff line number Diff line change
Expand Up @@ -2146,12 +2146,8 @@ object x:
v + 1
})
>>>
Idempotency violated
object x:
- val y = List(1).map(v =>
+ val y = List(1).map(
+ v =>
println(v)
- v + 1
- )
+ v + 1)
object x:
val y = List(1).map(v =>
println(v)
v + 1
)

0 comments on commit d33c573

Please sign in to comment.