diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index b692774f39f5..e2fdfe5d263f 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -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 = @@ -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() @@ -3747,7 +3747,7 @@ object Parsers { /** with Template, with EOL 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)) @@ -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)) } diff --git a/compiler/test/dotty/tools/dotc/CompilationTests.scala b/compiler/test/dotty/tools/dotc/CompilationTests.scala index 1bb4547c8953..ff98ce498d35 100644 --- a/compiler/test/dotty/tools/dotc/CompilationTests.scala +++ b/compiler/test/dotty/tools/dotc/CompilationTests.scala @@ -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() } diff --git a/tests/rewrites/i11895.scala b/tests/rewrites/i11895.scala new file mode 100644 index 000000000000..7980cbca09dc --- /dev/null +++ b/tests/rewrites/i11895.scala @@ -0,0 +1,8 @@ +object test4 { + + class MyEnum + + given scala.util.CommandLineParser.FromString[MyEnum] with { + def fromString(s: String): MyEnum = ??? + } +} \ No newline at end of file