File tree 4 files changed +20
-1
lines changed
compiler/src/dotty/tools/dotc
4 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -77,6 +77,7 @@ class Driver {
77
77
val ictx = rootCtx.fresh
78
78
val summary = command.distill(args, ictx.settings)(ictx.settingsState)(using ictx)
79
79
ictx.setSettings(summary.sstate)
80
+ Feature .checkExperimentalFlags(using ictx)
80
81
MacroClassLoader .init(ictx)
81
82
Positioned .init(using ictx)
82
83
Original file line number Diff line number Diff line change @@ -279,6 +279,10 @@ trait TreeInfo[T >: Untyped <: Type] { self: Trees.Instance[T] =>
279
279
280
280
def isLanguageImport (path : Tree ): Boolean = languageImport(path).isDefined
281
281
282
+ def isExperimentalImport (path : Tree ): Boolean = languageImport(path) match
283
+ case Some (nme.experimental) => true
284
+ case _ => false
285
+
282
286
/** The underlying pattern ignoring any bindings */
283
287
def unbind (x : Tree ): Tree = unsplice(x) match {
284
288
case Bind (_, y) => unbind(y)
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ object Feature:
28
28
val symbolLiterals = deprecated(" symbolLiterals" )
29
29
val fewerBraces = experimental(" fewerBraces" )
30
30
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
32
32
*
33
33
* -language:<prefix>feature
34
34
*
@@ -97,4 +97,15 @@ object Feature:
97
97
else
98
98
false
99
99
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
+
100
111
end Feature
Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ import config.Feature
32
32
import config .Feature .{sourceVersion , migrateTo3 }
33
33
import config .SourceVersion ._
34
34
import config .SourceVersion
35
+ import config .Properties
35
36
36
37
object Parsers {
37
38
@@ -3079,6 +3080,8 @@ object Parsers {
3079
3080
val imp = Import (tree, selectors)
3080
3081
if isLanguageImport(tree) then
3081
3082
in.languageImportContext = in.languageImportContext.importContext(imp, NoSymbol )
3083
+ if isExperimentalImport(tree) && ! Properties .experimental then
3084
+ report.error(Feature .experimentalWarningMessage, imp.srcPos)
3082
3085
for
3083
3086
case ImportSelector (id @ Ident (imported), EmptyTree , _) <- selectors
3084
3087
if allSourceVersionNames.contains(imported)
You can’t perform that action at this time.
0 commit comments