Skip to content
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

Fewer braces are part of the language from 3.3.x #14561

Closed
wants to merge 4 commits into from
Closed
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
1 change: 0 additions & 1 deletion compiler/src/dotty/tools/dotc/config/Feature.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ object Feature:
val dependent = experimental("dependent")
val erasedDefinitions = experimental("erasedDefinitions")
val symbolLiterals = deprecated("symbolLiterals")
val fewerBraces = experimental("fewerBraces")
val saferExceptions = experimental("saferExceptions")

/** Is `feature` enabled by by a command-line setting? The enabling setting is
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/config/ScalaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ trait AllScalaSettings extends CommonScalaSettings, PluginSettings, VerboseSetti
val oldSyntax: Setting[Boolean] = BooleanSetting("-old-syntax", "Require `(...)` around conditions.")
val indent: Setting[Boolean] = BooleanSetting("-indent", "Together with -rewrite, remove {...} syntax when possible due to significant indentation.")
val noindent: Setting[Boolean] = BooleanSetting("-no-indent", "Require classical {...} syntax, indentation is not significant.", aliases = List("-noindent"))
val YindentColons: Setting[Boolean] = BooleanSetting("-Yindent-colons", "(disabled: use -language:experimental.fewerBraces instead)")
val YindentColons: Setting[Boolean] = BooleanSetting("-Yindent-colons", "(disabled: colons can always indent from Scala v3.2.x)")

/* Decompiler settings */
val printTasty: Setting[Boolean] = BooleanSetting("-print-tasty", "Prints the raw tasty.", aliases = List("--print-tasty"))
Expand Down
12 changes: 6 additions & 6 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ object Parsers {
}
})
canRewrite &= (in.isAfterLineEnd || statCtdTokens.contains(in.token)) // test (5)
if (canRewrite && (!underColonSyntax || in.fewerBracesEnabled)) {
if (canRewrite && !underColonSyntax) {
val openingPatchStr =
if !colonRequired then ""
else if testChar(startOpening - 1, Chars.isOperatorPart(_)) then " :"
Expand Down Expand Up @@ -2252,8 +2252,8 @@ object Parsers {
* | SimpleExpr `.` MatchClause
* | SimpleExpr (TypeArgs | NamedTypeArgs)
* | SimpleExpr1 ArgumentExprs
* | SimpleExpr1 `:` IndentedExpr -- under language.experimental.fewerBraces
* | SimpleExpr1 FunParams (‘=>’ | ‘?=>’) IndentedExpr -- under language.experimental.fewerBraces
* | SimpleExpr1 `:` IndentedExpr
* | SimpleExpr1 FunParams (‘=>’ | ‘?=>’) IndentedExpr
* IndentedExpr ::= indent (CaseClauses | Block) outdent
* Quoted ::= ‘'’ ‘{’ Block ‘}’
* | ‘'’ ‘[’ Type ‘]’
Expand Down Expand Up @@ -2322,7 +2322,7 @@ object Parsers {
case LPAREN if canApply =>
val app = atSpan(startOffset(t), in.offset) {
val argExprs @ (args, isUsing) = argumentExprs()
if !isUsing && in.isArrow && location != Location.InGuard && in.fewerBracesEnabled then
if !isUsing && in.isArrow && location != Location.InGuard then
val params = convertToParams(Tuple(args))
if params.forall(_.name != nme.ERROR) then
applyToClosure(t, in.offset, params)
Expand All @@ -2336,13 +2336,13 @@ object Parsers {
val app = atSpan(startOffset(t), in.offset) { mkApply(t, argumentExprs()) }
simpleExprRest(app, location, canApply = true)
case USCORE =>
if in.lookahead.isArrow && location != Location.InGuard && in.fewerBracesEnabled then
if in.lookahead.isArrow && location != Location.InGuard then
val app = applyToClosure(t, in.offset, convertToParams(wildcardIdent()))
simpleExprRest(app, location, canApply = true)
else
atSpan(startOffset(t), in.skipToken()) { PostfixOp(t, Ident(nme.WILDCARD)) }
case IDENTIFIER
if !in.isOperator && in.lookahead.isArrow && location != Location.InGuard && in.fewerBracesEnabled =>
if !in.isOperator && in.lookahead.isArrow && location != Location.InGuard =>
val app = applyToClosure(t, in.offset, convertToParams(termIdent()))
simpleExprRest(app, location, canApply = true)
case _ =>
Expand Down
11 changes: 1 addition & 10 deletions compiler/src/dotty/tools/dotc/parsing/Scanners.scala
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,6 @@ object Scanners {
def featureEnabled(name: TermName) = Feature.enabled(name)(using languageImportContext)
def erasedEnabled = featureEnabled(Feature.erasedDefinitions)

private var fewerBracesEnabledCache = false
private var fewerBracesEnabledCtx: Context = NoContext

def fewerBracesEnabled =
if fewerBracesEnabledCtx ne myLanguageImportContext then
fewerBracesEnabledCache = featureEnabled(Feature.fewerBraces)
fewerBracesEnabledCtx = myLanguageImportContext
fewerBracesEnabledCache

/** All doc comments kept by their end position in a `Map`.
*
* Note: the map is necessary since the comments are looked up after an
Expand Down Expand Up @@ -655,7 +646,7 @@ object Scanners {
case END =>
if !isEndMarker then token = IDENTIFIER
case COLON =>
if fewerBracesEnabled then observeColonEOL()
observeColonEOL()
case RBRACE | RPAREN | RBRACKET =>
closeIndented()
case EOF =>
Expand Down
13 changes: 0 additions & 13 deletions compiler/test/dotty/tools/repl/ReplCompilerTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -243,24 +243,11 @@ class ReplCompilerTests extends ReplTest:

@Test def i14491 =
initially {
run("import language.experimental.fewerBraces")
} andThen {
run("""|val x = Seq(7,8,9).apply:
| 1
|""".stripMargin)
assertEquals("val x: Int = 8", storedOutput().trim)
}
initially {
run("""|import language.experimental.fewerBraces
|import language.experimental.fewerBraces as _
|""".stripMargin)
} andThen {
run("""|val x = Seq(7,8,9).apply:
| 1
|""".stripMargin)
assert("expected error if fewerBraces is unimported",
lines().exists(_.contains("missing arguments for method apply")))
}

object ReplCompilerTests:

Expand Down
4 changes: 2 additions & 2 deletions docs/_docs/internals/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ SimpleExpr ::= SimpleRef
| SimpleExpr ‘.’ MatchClause
| SimpleExpr TypeArgs TypeApply(expr, args)
| SimpleExpr ArgumentExprs Apply(expr, args)
| SimpleExpr ‘:’ IndentedExpr -- under language.experimental.fewerBraces
| SimpleExpr FunParams (‘=>’ | ‘?=>’) IndentedExpr -- under language.experimental.fewerBraces
| SimpleExpr ‘:’ IndentedExpr
| SimpleExpr FunParams (‘=>’ | ‘?=>’) IndentedExpr
| SimpleExpr ‘_’ PostfixOp(expr, _) (to be dropped)
| XmlExpr -- to be dropped
IndentedExpr ::= indent CaseClauses | Block outdent
Expand Down
1 change: 0 additions & 1 deletion docs/_docs/reference/experimental/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ All experimental language features can be found under the `scala.language.experi
They are enabled by importing the feature or using the `-language` compiler flag.

* [`erasedDefinitions`](./erased-defs.md): Enable support for `erased` modifier.
* `fewerBraces`: Enable support for using indentation for arguments.
* [`genericNumberLiterals`](./numeric-literals.md): Enable support for generic number literals.
* [`namedTypeArguments`](./named-typeargs.md): Enable support for named type arguments
* [`saferExceptions`](./canthrow.md): Enable support for checked exceptions.
Expand Down

This file was deleted.

6 changes: 0 additions & 6 deletions docs/_docs/reference/other-new-features/indentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -416,12 +416,6 @@ The `-indent` option only works on [new-style syntax](./control-syntax.md). So t

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.

To allow such arguments to be written without braces, a variant of the indentation scheme is implemented under language import
```scala
import language.experimental.fewerBraces
```
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:

```scala
times(10):
println("ah")
Expand Down
5 changes: 0 additions & 5 deletions library/src/scala/runtime/stdLibPatches/language.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ object language:
@compileTimeOnly("`erasedDefinitions` can only be used at compile time in import statements")
object erasedDefinitions

/** Experimental support for using indentation for arguments
*/
@compileTimeOnly("`fewerBraces` can only be used at compile time in import statements")
object fewerBraces

/** Experimental support for typechecked exception capabilities
*
* @see [[https://dotty.epfl.ch/docs/reference/experimental/canthrow]]
Expand Down
2 changes: 2 additions & 0 deletions project/MiMaFilters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ object MiMaFilters {
ProblemFilters.exclude[MissingClassProblem]("scala.compiletime.ops.long$"),
ProblemFilters.exclude[ReversedMissingMethodProblem]("scala.quoted.Quotes#reflectModule#CompilationInfoModule.XmacroSettings"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.quoted.Quotes#reflectModule#CompilationInfoModule.XmacroSettings"),
ProblemFilters.exclude[MissingFieldProblem]("scala.runtime.stdLibPatches.language#experimental.fewerBraces"),
ProblemFilters.exclude[MissingClassProblem]("scala.runtime.stdLibPatches.language$experimental$fewerBraces$"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.deriving.Mirror.fromProductTyped"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.deriving.Mirror.fromTuple"),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,38 @@ import annotation.experimental

@experimental
object Object1:
import language.experimental.fewerBraces
import language.experimental.namedTypeArguments
import language.experimental.genericNumberLiterals
import language.experimental.erasedDefinitions
erased def f = 1

object Object2:
import language.experimental.fewerBraces // error
import language.experimental.namedTypeArguments // error
import language.experimental.genericNumberLiterals // error
import language.experimental.erasedDefinitions
erased def f = 1

@experimental
object Class1:
import language.experimental.fewerBraces
import language.experimental.namedTypeArguments
import language.experimental.genericNumberLiterals
import language.experimental.erasedDefinitions
erased def f = 1

object Class2:
import language.experimental.fewerBraces // error
import language.experimental.namedTypeArguments // error
import language.experimental.genericNumberLiterals // error
import language.experimental.erasedDefinitions
erased def f = 1

@experimental
def fun1 =
import language.experimental.fewerBraces
import language.experimental.namedTypeArguments
import language.experimental.genericNumberLiterals
import language.experimental.erasedDefinitions
erased def f = 1

def fun2 =
import language.experimental.fewerBraces // error
import language.experimental.namedTypeArguments // error
import language.experimental.genericNumberLiterals // error
import language.experimental.erasedDefinitions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
import annotation.experimental

class Class1:
import language.experimental.fewerBraces // error
import language.experimental.namedTypeArguments // error
import language.experimental.genericNumberLiterals // error
import language.experimental.erasedDefinitions // ok: only check at erased definition
@experimental def f = 1
def g = 1

object Object1:
import language.experimental.fewerBraces // error
import language.experimental.namedTypeArguments // error
import language.experimental.genericNumberLiterals // error
import language.experimental.erasedDefinitions // ok: only check at erased definition
@experimental def f = 1
def g = 1

def fun1 =
import language.experimental.fewerBraces // error
import language.experimental.namedTypeArguments // error
import language.experimental.genericNumberLiterals // error
import language.experimental.erasedDefinitions // ok: only check at erased definition
@experimental def f = 1
def g = 1

val value1 =
import language.experimental.fewerBraces // error
import language.experimental.namedTypeArguments // error
import language.experimental.genericNumberLiterals // error
import language.experimental.erasedDefinitions // ok: only check at erased definition
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
import annotation.experimental

class Class1:
import language.experimental.fewerBraces // error
import language.experimental.namedTypeArguments // error
import language.experimental.genericNumberLiterals // error
import language.experimental.erasedDefinitions // ok: only check at erased definition

object Object1:
import language.experimental.fewerBraces // error
import language.experimental.namedTypeArguments // error
import language.experimental.genericNumberLiterals // error
import language.experimental.erasedDefinitions // ok: only check at erased definition

def fun1 =
import language.experimental.fewerBraces // error
import language.experimental.namedTypeArguments // error
import language.experimental.genericNumberLiterals // error
import language.experimental.erasedDefinitions // ok: only check at erased definition

val value1 =
import language.experimental.fewerBraces // error
import language.experimental.namedTypeArguments // error
import language.experimental.genericNumberLiterals // error
import language.experimental.erasedDefinitions // ok: only check at erased definition
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
import annotation.experimental

class Class1:
import language.experimental.fewerBraces // error
import language.experimental.namedTypeArguments // error
import language.experimental.genericNumberLiterals // error
import language.experimental.erasedDefinitions // ok: only check at erased definition
@experimental def f = 1

object Object1:
import language.experimental.fewerBraces // error
import language.experimental.namedTypeArguments // error
import language.experimental.genericNumberLiterals // error
import language.experimental.erasedDefinitions // ok: only check at erased definition
@experimental def f = 1

def fun1 =
import language.experimental.fewerBraces // error
import language.experimental.namedTypeArguments // error
import language.experimental.genericNumberLiterals // error
import language.experimental.erasedDefinitions // ok: only check at erased definition
@experimental def f = 1

val value1 =
import language.experimental.fewerBraces // error
import language.experimental.namedTypeArguments // error
import language.experimental.genericNumberLiterals // error
import language.experimental.erasedDefinitions // ok: only check at erased definition
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import annotation.experimental

package foo {
import language.experimental.fewerBraces // error
import language.experimental.namedTypeArguments // error
import language.experimental.genericNumberLiterals // error
import language.experimental.erasedDefinitions // ok: only check at erased definition
Expand All @@ -13,7 +12,6 @@ package foo {

package foo2 {
// ok: all definitions are top-level @experimental
import language.experimental.fewerBraces
import language.experimental.namedTypeArguments
import language.experimental.genericNumberLiterals
import language.experimental.erasedDefinitions
Expand Down
Loading