Skip to content

Commit 183b254

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 43f8cdb commit 183b254

File tree

5 files changed

+11
-17
lines changed

5 files changed

+11
-17
lines changed

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

-9
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

+5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ enum SourceVersion:
3131

3232
def isAtMost(v: SourceVersion) = stable.ordinal <= v.ordinal
3333

34+
def enablesFewerBraces = isAtLeast(`3.3`)
35+
def enablesClauseInterleaving = isAtLeast(`3.6`)
36+
def enablesNewGivens = isAtLeast(`3.6`)
37+
def enablesNamedTuples = isAtLeast(`3.6`)
38+
3439
object SourceVersion extends Property.Key[SourceVersion]:
3540
def defaultSourceVersion = `3.7`
3641

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ object Parsers {
885885
}
886886
})
887887
canRewrite &= (in.isAfterLineEnd || statCtdTokens.contains(in.token)) // test (5)
888-
if canRewrite && (!underColonSyntax || Feature.fewerBracesEnabled) then
888+
if canRewrite && (!underColonSyntax || sourceVersion.enablesFewerBraces) then
889889
val openingPatchStr =
890890
if !colonRequired then ""
891891
else if testChar(startOpening - 1, Chars.isOperatorPart(_)) then " :"
@@ -1165,7 +1165,7 @@ object Parsers {
11651165
* body
11661166
*/
11671167
def isColonLambda =
1168-
Feature.fewerBracesEnabled && in.token == COLONfollow && followingIsLambdaAfterColon()
1168+
sourceVersion.enablesFewerBraces && in.token == COLONfollow && followingIsLambdaAfterColon()
11691169

11701170
/** operand { infixop operand | MatchClause } [postfixop],
11711171
*
@@ -3969,7 +3969,7 @@ object Parsers {
39693969
val ident = termIdent()
39703970
var name = ident.name.asTermName
39713971
val paramss =
3972-
if Feature.clauseInterleavingEnabled(using in.languageImportContext) then
3972+
if sourceVersion.enablesClauseInterleaving then
39733973
typeOrTermParamClauses(ParamOwner.Def, numLeadParams)
39743974
else
39753975
val tparams = typeParamClauseOpt(ParamOwner.Def)

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

+2-2
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}
@@ -664,7 +664,7 @@ object Scanners {
664664
if token == COLONop && inTemplate then
665665
report.deprecationWarning(em"`:` after symbolic operator is deprecated; use backticks around operator instead", sourcePos(offset))
666666
true
667-
else token == COLONfollow && (inTemplate || fewerBracesEnabled)
667+
else token == COLONfollow && (inTemplate || sourceVersion.enablesFewerBraces)
668668
if enabled then
669669
peekAhead()
670670
val atEOL = isAfterLineEnd || token == EOF
+1-3
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)