Skip to content

Commit

Permalink
TreeSyntax: separate block in scala3 stats (#3276)
Browse files Browse the repository at this point in the history
Follow-on to #3139 and #3269.
  • Loading branch information
kitbellew committed Jul 26, 2023
1 parent 6345cbb commit 16819e5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ object TreeSyntax {
case _: Decl.Val | _: Decl.Var | _: Decl.Def | _: Defn.Type | _: Term.Ref | _: Member.Apply |
_: Term.Ascribe | _: Term.Tuple | _: Term.New | _: Term.Interpolate | _: Term.Xml |
_: Lit =>
true
!dialect.allowSignificantIndentation
case t: Term.Do => false
case t: Tree.WithBody => guessNeedsLineSep(t.body)
case t: Stat.WithTemplate => t.templ.self.isEmpty && t.templ.stats.isEmpty
Expand Down Expand Up @@ -1121,8 +1121,7 @@ object TreeSyntax {
builder.result()
}

implicit def syntaxStats: Syntax[Seq[Stat]] =
if (dialect.allowSignificantIndentation) Syntax(x => r(x.map(i(_)))) else Syntax(printStats)
implicit def syntaxStats: Syntax[Seq[Stat]] = Syntax(printStats)

}
def apply[T <: Tree](dialect: Dialect): Syntax[T] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3333,6 +3333,7 @@ class SignificantIndentationSuite extends BaseDottySuite {
val layout =
"""|class DerivationSpec {
| case class Foo()
|
| {
| deriveEncoder[Foo]
| }
Expand Down Expand Up @@ -3360,10 +3361,7 @@ class SignificantIndentationSuite extends BaseDottySuite {
)
)
)
// code parses as specified tree
checkStat(code, layout)(tree)
// however, the parsed layout itself has different syntax (and, hence, tree)
assertNotEquals(parseStat(layout, implicitly[Dialect]).reprint, layout)
runTestAssert[Stat](code, Some(layout))(tree)
}

test("blank after template 2") {
Expand All @@ -3383,6 +3381,7 @@ class SignificantIndentationSuite extends BaseDottySuite {
val layout =
"""|class DerivationSpec {
| case class Foo() extends Bar
|
| {
| deriveEncoder[Foo]
| }
Expand Down Expand Up @@ -3410,10 +3409,7 @@ class SignificantIndentationSuite extends BaseDottySuite {
)
)
)
// code parses as specified tree
checkStat(code, layout)(tree)
// however, the parsed layout itself has different syntax (and, hence, tree)
assertNotEquals(parseStat(layout, implicitly[Dialect]).reprint, layout)
runTestAssert[Stat](code, Some(layout))(tree)
}

}

0 comments on commit 16819e5

Please sign in to comment.