Skip to content

Commit 3cf14cc

Browse files
oderskymichelou
authored andcommitted
Fix scala#11774: only enable experimental features for snapshot and nightly
1 parent addc603 commit 3cf14cc

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

compiler/src/dotty/tools/dotc/Driver.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class Driver {
7777
val ictx = rootCtx.fresh
7878
val summary = command.distill(args, ictx.settings)(ictx.settingsState)(using ictx)
7979
ictx.setSettings(summary.sstate)
80+
Feature.checkExperimentalFlags(using ictx)
8081
MacroClassLoader.init(ictx)
8182
Positioned.init(using ictx)
8283

compiler/src/dotty/tools/dotc/ast/TreeInfo.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,10 @@ trait TreeInfo[T >: Untyped <: Type] { self: Trees.Instance[T] =>
279279

280280
def isLanguageImport(path: Tree): Boolean = languageImport(path).isDefined
281281

282+
def isExperimentalImport(path: Tree): Boolean = languageImport(path) match
283+
case Some(nme.experimental) => true
284+
case _ => false
285+
282286
/** The underlying pattern ignoring any bindings */
283287
def unbind(x: Tree): Tree = unsplice(x) match {
284288
case Bind(_, y) => unbind(y)

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ object Feature:
2828
val symbolLiterals = deprecated("symbolLiterals")
2929
val fewerBraces = experimental("fewerBraces")
3030

31-
/** Is `feature` enabled by by a command-line setting? The enabling setting is
31+
/** Is `feature` enabled by by a command-line setting? The enabling setting is
3232
*
3333
* -language:<prefix>feature
3434
*
@@ -97,4 +97,15 @@ object Feature:
9797
else
9898
false
9999

100+
val experimentalWarningMessage = "Experimental features may only be used with nightly or snapshot version of compiler."
101+
102+
/** Check that experimental compiler options are only set for snapshot or nightly compiler versions. */
103+
def checkExperimentalFlags(using Context): Unit =
104+
if !Properties.experimental then
105+
val features = ctx.settings.language.value.filter(_.startsWith("experimental."))
106+
if features.nonEmpty then
107+
report.error(
108+
i"""$experimentalWarningMessage
109+
|The experimental language features were enabled via -language:$features%,%""")
110+
100111
end Feature

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import config.Feature
3232
import config.Feature.{sourceVersion, migrateTo3}
3333
import config.SourceVersion._
3434
import config.SourceVersion
35+
import config.Properties
3536

3637
object Parsers {
3738

@@ -3079,6 +3080,8 @@ object Parsers {
30793080
val imp = Import(tree, selectors)
30803081
if isLanguageImport(tree) then
30813082
in.languageImportContext = in.languageImportContext.importContext(imp, NoSymbol)
3083+
if isExperimentalImport(tree) && !Properties.experimental then
3084+
report.error(Feature.experimentalWarningMessage, imp.srcPos)
30823085
for
30833086
case ImportSelector(id @ Ident(imported), EmptyTree, _) <- selectors
30843087
if allSourceVersionNames.contains(imported)

0 commit comments

Comments
 (0)