Skip to content

Commit 9735887

Browse files
committed
Standardize how previously experimental features are handled
If a feature was previously experimental and is now standard, we change any tests for that feature to be only dependent on the source version where the feature was standardized. Language imports in old source versions will no longer enable the feature. (And these language imports also come with a deprecation message). If a feature was previously experimental and is now dropped, the feature becomes unavailable also in old versions. The motivation to do it this way is to insist that experimental features are ephemeral. We should not be able to rely on an experimental feature forever in an old version. This commit implements this policy for fewerBraces and clauseInterleaving. Two implemented extensions (relaxedExtensionImports, betterMatchTypeExtractors) already implemented it before.
1 parent 56a384f commit 9735887

File tree

5 files changed

+11
-17
lines changed

5 files changed

+11
-17
lines changed

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ object Feature:
2828
val dependent = experimental("dependent")
2929
val erasedDefinitions = experimental("erasedDefinitions")
3030
val symbolLiterals = deprecated("symbolLiterals")
31-
val fewerBraces = experimental("fewerBraces")
3231
val saferExceptions = experimental("saferExceptions")
3332
val clauseInterleaving = experimental("clauseInterleaving")
3433
val pureFunctions = experimental("pureFunctions")
@@ -60,9 +59,7 @@ object Feature:
6059
(dependent, "Allow dependent method types"),
6160
(erasedDefinitions, "Allow erased definitions"),
6261
(symbolLiterals, "Allow symbol literals"),
63-
(fewerBraces, "Enable support for using indentation for arguments"),
6462
(saferExceptions, "Enable safer exceptions"),
65-
(clauseInterleaving, "Enable clause interleaving"),
6663
(pureFunctions, "Enable pure functions for capture checking"),
6764
(captureChecking, "Enable experimental capture checking"),
6865
(into, "Allow into modifier on parameter types"),
@@ -124,9 +121,6 @@ object Feature:
124121

125122
def namedTypeArgsEnabled(using Context) = enabled(namedTypeArguments)
126123

127-
def clauseInterleavingEnabled(using Context) =
128-
sourceVersion.isAtLeast(`3.6`) || enabled(clauseInterleaving)
129-
130124
def betterForsEnabled(using Context) = enabled(betterFors)
131125

132126
def genericNumberLiteralsEnabled(using Context) = enabled(genericNumberLiterals)
@@ -169,9 +163,6 @@ object Feature:
169163
def migrateTo3(using Context): Boolean =
170164
sourceVersion == `3.0-migration`
171165

172-
def fewerBracesEnabled(using Context) =
173-
sourceVersion.isAtLeast(`3.3`) || enabled(fewerBraces)
174-
175166
/** If current source migrates to `version`, issue given warning message
176167
* and return `true`, otherwise return `false`.
177168
*/

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ enum SourceVersion:
2828

2929
def isAtMost(v: SourceVersion) = stable.ordinal <= v.ordinal
3030

31+
def enablesFewerBraces = isAtLeast(`3.3`)
32+
def enablesClauseInterleaving = isAtLeast(`3.6`)
33+
def enablesNewGivens = isAtLeast(`3.6`)
34+
def enablesNamedTuples = isAtLeast(`3.6`)
35+
3136
object SourceVersion extends Property.Key[SourceVersion]:
3237
def defaultSourceVersion = `3.6`
3338

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@ object Parsers {
868868
}
869869
})
870870
canRewrite &= (in.isAfterLineEnd || statCtdTokens.contains(in.token)) // test (5)
871-
if canRewrite && (!underColonSyntax || Feature.fewerBracesEnabled) then
871+
if canRewrite && (!underColonSyntax || sourceVersion.enablesFewerBraces) then
872872
val openingPatchStr =
873873
if !colonRequired then ""
874874
else if testChar(startOpening - 1, Chars.isOperatorPart(_)) then " :"
@@ -1119,7 +1119,7 @@ object Parsers {
11191119
* body
11201120
*/
11211121
def isColonLambda =
1122-
Feature.fewerBracesEnabled && in.token == COLONfollow && followingIsLambdaAfterColon()
1122+
sourceVersion.enablesFewerBraces && in.token == COLONfollow && followingIsLambdaAfterColon()
11231123

11241124
/** operand { infixop operand | MatchClause } [postfixop],
11251125
*
@@ -3914,7 +3914,7 @@ object Parsers {
39143914
val ident = termIdent()
39153915
var name = ident.name.asTermName
39163916
val paramss =
3917-
if Feature.clauseInterleavingEnabled(using in.languageImportContext) then
3917+
if sourceVersion.enablesClauseInterleaving then
39183918
typeOrTermParamClauses(ParamOwner.Def, numLeadParams)
39193919
else
39203920
val tparams = typeParamClauseOpt(ParamOwner.Def)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import scala.collection.mutable
1717
import scala.collection.immutable.SortedMap
1818
import rewrites.Rewrites.patch
1919
import config.Feature
20-
import config.Feature.{migrateTo3, fewerBracesEnabled}
20+
import config.Feature.migrateTo3
2121
import config.SourceVersion.{`3.0`, `3.0-migration`}
2222
import config.MigrationVersion
2323
import reporting.{NoProfile, Profile, Message}
@@ -663,7 +663,7 @@ object Scanners {
663663
if token == COLONop && inTemplate then
664664
report.deprecationWarning(em"`:` after symbolic operator is deprecated; use backticks around operator instead", sourcePos(offset))
665665
true
666-
else token == COLONfollow && (inTemplate || fewerBracesEnabled)
666+
else token == COLONfollow && (inTemplate || sourceVersion.enablesFewerBraces)
667667
if enabled then
668668
peekAhead()
669669
val atEOL = isAfterLineEnd || token == EOF
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//> using options --source 3.5
2-
3-
import scala.language.experimental.clauseInterleaving
1+
//> using options --source 3.6
42

53
def ba[A](x: A)[B](using B): B = summon[B]

0 commit comments

Comments
 (0)