Skip to content

Commit cd01d25

Browse files
committed
Replace -Yindent-colons with language import
Replace -Yindent-colons with language import import language.experimental.fewerBraces
1 parent 20d2e2a commit cd01d25

File tree

8 files changed

+23
-10
lines changed

8 files changed

+23
-10
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ object Feature:
2525

2626
val dependent = experimental("dependent")
2727
val erasedDefinitions = experimental("erasedDefinitions")
28-
val symbolLiterals: TermName = deprecated("symbolLiterals")
28+
val symbolLiterals = deprecated("symbolLiterals")
29+
val fewerBraces = experimental("fewerBraces")
2930

3031
/** Is `feature` enabled by by a command-line setting? The enabling setting is
3132
*

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class ScalaSettings extends Settings.SettingGroup with CommonScalaSettings {
121121
val oldSyntax: Setting[Boolean] = BooleanSetting("-old-syntax", "Require `(...)` around conditions.")
122122
val indent: Setting[Boolean] = BooleanSetting("-indent", "Together with -rewrite, remove {...} syntax when possible due to significant indentation.")
123123
val noindent: Setting[Boolean] = BooleanSetting("-no-indent", "Require classical {...} syntax, indentation is not significant.", aliases = List("-noindent"))
124-
val YindentColons: Setting[Boolean] = BooleanSetting("-Yindent-colons", "Allow colons at ends-of-lines to start indentation blocks.")
124+
val YindentColons: Setting[Boolean] = BooleanSetting("-Yindent-colons", "(disabled: use -language:experimental.fewerBraces instead)")
125125

126126
/** Decompiler settings */
127127
val printTasty: Setting[Boolean] = BooleanSetting("-print-tasty", "Prints the raw tasty.", aliases = List("--print-tasty"))

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ object Parsers {
743743
}
744744
})
745745
canRewrite &= (in.isAfterLineEnd || statCtdTokens.contains(in.token)) // test (5)
746-
if (canRewrite && (!underColonSyntax || in.colonSyntax)) {
746+
if (canRewrite && (!underColonSyntax || in.fewerBracesEnabled)) {
747747
val openingPatchStr =
748748
if !colonRequired then ""
749749
else if testChar(startOpening - 1, Chars.isOperatorPart(_)) then " :"

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,6 @@ object Scanners {
182182
((if (Config.defaultIndent) !noindentSyntax else ctx.settings.indent.value)
183183
|| rewriteNoIndent)
184184
&& !isInstanceOf[LookaheadScanner]
185-
val colonSyntax =
186-
ctx.settings.YindentColons.value
187-
|| rewriteNoIndent
188185

189186
if (rewrite) {
190187
val s = ctx.settings
@@ -201,6 +198,15 @@ object Scanners {
201198
def featureEnabled(name: TermName) = Feature.enabled(name)(using languageImportContext)
202199
def erasedEnabled = featureEnabled(Feature.erasedDefinitions) || ctx.settings.YerasedTerms.value
203200

201+
private var fewerBracesEnabledCache = false
202+
private var fewerBracesEnabledCtx: Context = NoContext
203+
204+
def fewerBracesEnabled =
205+
if fewerBracesEnabledCtx ne myLanguageImportContext then
206+
fewerBracesEnabledCache = featureEnabled(Feature.fewerBraces)
207+
fewerBracesEnabledCtx = myLanguageImportContext
208+
fewerBracesEnabledCache
209+
204210
/** All doc comments kept by their end position in a `Map`.
205211
*
206212
* Note: the map is necessary since the comments are looked up after an
@@ -635,7 +641,7 @@ object Scanners {
635641
else
636642
reset()
637643
case COLON =>
638-
if colonSyntax then observeColonEOL()
644+
if fewerBracesEnabled then observeColonEOL()
639645
case RBRACE | RPAREN | RBRACKET =>
640646
closeIndented()
641647
case EOF =>

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ class CompilationTests {
4949
defaultOptions.and("-nowarn", "-Xfatal-warnings")
5050
),
5151
compileFile("tests/pos-special/typeclass-scaling.scala", defaultOptions.and("-Xmax-inlines", "40")),
52-
compileFile("tests/pos-special/indent-colons.scala", defaultOptions.and("-Yindent-colons")),
5352
compileFile("tests/pos-special/i7296.scala", defaultOptions.and("-source", "future", "-deprecation", "-Xfatal-warnings")),
5453
compileFile("tests/pos-special/notNull.scala", defaultOptions.and("-Yexplicit-nulls")),
5554
compileDir("tests/pos-special/adhoc-extension", defaultOptions.and("-source", "future", "-feature", "-Xfatal-warnings")),

docs/docs/reference/other-new-features/indentation.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,11 @@ The `-indent` option only works on [new-style syntax](./control-syntax.md). So t
391391

392392
Generally, the possible indentation regions coincide with those regions where braces `{...}` are also legal, no matter whether the braces enclose an expression or a set of definitions. There is one exception, though: Arguments to function can be enclosed in braces but they cannot be simply indented instead. Making indentation always significant for function arguments would be too restrictive and fragile.
393393

394-
To allow such arguments to be written without braces, a variant of the indentation scheme is implemented under
395-
option `-Yindent-colons`. This variant is more contentious and less stable than the rest of the significant indentation scheme. In this variant, a colon `:` at the end of a line is also one of the possible tokens that opens an indentation region. Examples:
394+
To allow such arguments to be written without braces, a variant of the indentation scheme is implemented under language import
395+
```scala
396+
import language.experimental.fewerBraces
397+
```
398+
This variant is more contentious and less stable than the rest of the significant indentation scheme. In this variant, a colon `:` at the end of a line is also one of the possible tokens that opens an indentation region. Examples:
396399

397400
```scala
398401
times(10):

library/src/scala/runtime/stdLibPatches/language.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ object language:
4343
*/
4444
object erasedDefinitions
4545

46+
/** Experimental support for using indentation for arguments
47+
*/
48+
object fewerBraces
4649
end experimental
4750

4851
/** The deprecated object contains features that are no longer officially suypported in Scala.

tests/pos-special/indent-colons.scala renamed to tests/pos/indent-colons.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import language.experimental.fewerBraces
12
object Test:
23

34
locally:

0 commit comments

Comments
 (0)