Skip to content

Commit 585f424

Browse files
authored
Merge pull request #11908 from dotty-staging/fix-11895
Fix rewrite indent for given definitions
2 parents e78e97a + 7288f8b commit 585f424

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,7 +1237,7 @@ object Parsers {
12371237

12381238
def colonAtEOLOpt(): Unit = {
12391239
possibleColonOffset = in.lastOffset
1240-
if (in.token == COLONEOL) in.nextToken()
1240+
if in.token == COLONEOL then in.nextToken()
12411241
}
12421242

12431243
def argumentStart(): Unit =
@@ -3736,8 +3736,8 @@ object Parsers {
37363736
(EmptyValDef, Nil)
37373737
Template(constr, parents, derived, self, stats)
37383738

3739-
def templateBody(): (ValDef, List[Tree]) =
3740-
val r = inDefScopeBraces(templateStatSeq(), rewriteWithColon = true)
3739+
def templateBody(rewriteWithColon: Boolean = true): (ValDef, List[Tree]) =
3740+
val r = inDefScopeBraces(templateStatSeq(), rewriteWithColon)
37413741
if in.token == WITH then
37423742
syntaxError(EarlyDefinitionsNotSupported())
37433743
in.nextToken()
@@ -3747,7 +3747,7 @@ object Parsers {
37473747
/** with Template, with EOL <indent> interpreted */
37483748
def withTemplate(constr: DefDef, parents: List[Tree]): Template =
37493749
accept(WITH)
3750-
val (self, stats) = templateBody()
3750+
val (self, stats) = templateBody(rewriteWithColon = false)
37513751
Template(constr, parents, Nil, self, stats)
37523752
.withSpan(Span(constr.span.orElse(parents.head.span).start, in.lastOffset))
37533753

@@ -4000,7 +4000,7 @@ object Parsers {
40004000
EmptyTree
40014001
}
40024002

4003-
override def templateBody(): (ValDef, List[Thicket]) = {
4003+
override def templateBody(rewriteWithColon: Boolean): (ValDef, List[Thicket]) = {
40044004
skipBraces()
40054005
(EmptyValDef, List(EmptyTree))
40064006
}

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ class CompilationTests {
6868
compileFile("tests/rewrites/rewrites.scala", scala2CompatMode.and("-rewrite", "-indent")),
6969
compileFile("tests/rewrites/rewrites3x.scala", defaultOptions.and("-rewrite", "-source", "future-migration")),
7070
compileFile("tests/rewrites/i8982.scala", defaultOptions.and("-indent", "-rewrite")),
71-
compileFile("tests/rewrites/i9632.scala", defaultOptions.and("-indent", "-rewrite"))
71+
compileFile("tests/rewrites/i9632.scala", defaultOptions.and("-indent", "-rewrite")),
72+
compileFile("tests/rewrites/i11895.scala", defaultOptions.and("-indent", "-rewrite"))
7273
).checkRewrites()
7374
}
7475

tests/rewrites/i11895.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
object test4 {
2+
3+
class MyEnum
4+
5+
given scala.util.CommandLineParser.FromString[MyEnum] with {
6+
def fromString(s: String): MyEnum = ???
7+
}
8+
}

0 commit comments

Comments
 (0)