Skip to content

Commit 4716f4e

Browse files
committed
Introduce option to treat colon at eol as indentation start
A `:` at the end of a line starting an indentation region is now allowed only if option `-Yindent-colon` is set. Rewriting to colons is also subject to that setting.
1 parent dd29816 commit 4716f4e

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class ScalaSettings extends Settings.SettingGroup {
5252
val oldSyntax: Setting[Boolean] = BooleanSetting("-old-syntax", "Require `(...)` around conditions")
5353
val indent: Setting[Boolean] = BooleanSetting("-indent", "allow significant indentation")
5454
val noindent: Setting[Boolean] = BooleanSetting("-noindent", "require classical {...} syntax, indentation is not significant")
55+
val YindentColons: Setting[Boolean] = BooleanSetting("-Yindent-colons", "allow colons at ends-of-lines to start indentation blocks")
5556

5657
/** Decompiler settings */
5758
val printTasty: Setting[Boolean] = BooleanSetting("-print-tasty", "Prints the raw tasty.") withAbbreviation "--print-tasty"

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,7 @@ object Parsers {
710710
*/
711711
def bracesToIndented[T](body: => T): T = {
712712
val colonRequired = possibleColonOffset == in.lastOffset
713+
if colonRequired && !in.colonSyntax then return body
713714
val (startOpening, endOpening) = startingElimRegion(colonRequired)
714715
val isOutermost = in.currentRegion.isOutermost
715716
def allBraces(r: Region): Boolean = r match {

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,15 @@ object Scanners {
152152
val rewriteNoIndent = ctx.settings.noindent.value && rewrite
153153

154154
val noindentSyntax =
155-
ctx.settings.noindent.value ||
156-
ctx.settings.oldSyntax.value ||
157-
isScala2Mode
155+
ctx.settings.noindent.value
156+
|| ctx.settings.oldSyntax.value
157+
|| isScala2Mode
158158
val indentSyntax =
159-
(if (Config.defaultIndent) !noindentSyntax else ctx.settings.indent.value) ||
160-
rewriteNoIndent
159+
(if (Config.defaultIndent) !noindentSyntax else ctx.settings.indent.value)
160+
|| rewriteNoIndent
161+
val colonSyntax =
162+
ctx.settings.YindentColons.value
163+
|| rewriteNoIndent
161164

162165
if (rewrite) {
163166
val s = ctx.settings
@@ -590,7 +593,7 @@ object Scanners {
590593
lookahead()
591594
val atEOL = isAfterLineEnd
592595
reset()
593-
if (atEOL) token = COLONEOL
596+
if colonSyntax && atEOL then token = COLONEOL
594597
case EOF | RBRACE =>
595598
currentRegion match {
596599
case r: Indented if !r.isOutermost =>

compiler/src/dotty/tools/dotc/transform/Mixin.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,6 @@ class Mixin extends MiniPhase with SymTransformer { thisPhase =>
263263
transformFollowing(polyDefDef(mkForwarderSym(meth.asTerm, Bridge), forwarderRhsFn(meth)))
264264
}
265265

266-
267266
cpy.Template(impl)(
268267
constr =
269268
if (cls.is(Trait)) cpy.DefDef(impl.constr)(vparamss = Nil :: Nil)

0 commit comments

Comments
 (0)