Skip to content

Fix rewrite indent for given definitions #11908

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,7 @@ object Parsers {

def colonAtEOLOpt(): Unit = {
possibleColonOffset = in.lastOffset
if (in.token == COLONEOL) in.nextToken()
if in.token == COLONEOL then in.nextToken()
}

def argumentStart(): Unit =
Expand Down Expand Up @@ -3736,8 +3736,8 @@ object Parsers {
(EmptyValDef, Nil)
Template(constr, parents, derived, self, stats)

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

Expand Down Expand Up @@ -4000,7 +4000,7 @@ object Parsers {
EmptyTree
}

override def templateBody(): (ValDef, List[Thicket]) = {
override def templateBody(rewriteWithColon: Boolean): (ValDef, List[Thicket]) = {
skipBraces()
(EmptyValDef, List(EmptyTree))
}
Expand Down
3 changes: 2 additions & 1 deletion compiler/test/dotty/tools/dotc/CompilationTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ class CompilationTests {
compileFile("tests/rewrites/rewrites.scala", scala2CompatMode.and("-rewrite", "-indent")),
compileFile("tests/rewrites/rewrites3x.scala", defaultOptions.and("-rewrite", "-source", "future-migration")),
compileFile("tests/rewrites/i8982.scala", defaultOptions.and("-indent", "-rewrite")),
compileFile("tests/rewrites/i9632.scala", defaultOptions.and("-indent", "-rewrite"))
compileFile("tests/rewrites/i9632.scala", defaultOptions.and("-indent", "-rewrite")),
compileFile("tests/rewrites/i11895.scala", defaultOptions.and("-indent", "-rewrite"))
).checkRewrites()
}

Expand Down
8 changes: 8 additions & 0 deletions tests/rewrites/i11895.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
object test4 {

class MyEnum

given scala.util.CommandLineParser.FromString[MyEnum] with {
def fromString(s: String): MyEnum = ???
}
}