@@ -27,7 +27,16 @@ object Feature:
27
27
val erasedDefinitions = experimental(" erasedDefinitions" )
28
28
val symbolLiterals : TermName = deprecated(" symbolLiterals" )
29
29
30
- /** Is `feature` enabled by by a command-line setting? The enabling setting is
30
+ val experimentalWarningMessage = " Experimental features may only be used with nightly or snapshot version of compiler."
31
+
32
+ /** Experimental features are only enabled for snapshot and nightly version of compiler
33
+ */
34
+ def checkExperimentalFeature (feature : TermName ): Boolean =
35
+ feature match
36
+ case QualifiedName (nme.experimental, _) => Properties .experimental
37
+ case _ => true
38
+
39
+ /** Is `feature` enabled by by a command-line setting? The enabling setting is
31
40
*
32
41
* -language:<prefix>feature
33
42
*
@@ -55,9 +64,11 @@ object Feature:
55
64
* @param feature The name of the feature
56
65
* @param owner The prefix symbol (nested in `scala.language`) where the
57
66
* feature is defined.
67
+ *
68
+ * Note: Experimental features are only enabled for snapshot and nightly version of compiler.
58
69
*/
59
70
def enabled (feature : TermName )(using Context ): Boolean =
60
- enabledBySetting(feature) || enabledByImport(feature)
71
+ checkExperimentalFeature(feature) && ( enabledBySetting(feature) || enabledByImport(feature) )
61
72
62
73
/** Is auto-tupling enabled? */
63
74
def autoTuplingEnabled (using Context ): Boolean = ! enabled(nme.noAutoTupling)
@@ -70,6 +81,8 @@ object Feature:
70
81
71
82
def genericNumberLiteralsEnabled (using Context ) = enabled(genericNumberLiterals)
72
83
84
+ def erasedEnabled (using Context ) = enabled(Feature .erasedDefinitions)
85
+
73
86
def scala2ExperimentalMacroEnabled (using Context ) = enabled(scala2macros)
74
87
75
88
def sourceVersionSetting (using Context ): SourceVersion =
@@ -96,4 +109,14 @@ object Feature:
96
109
else
97
110
false
98
111
112
+ /** Check that experimental compiler options are only set with snapshot or nightly compiler version. */
113
+ def checkExperimentalFlags (using Context ): Unit =
114
+ if ! Properties .experimental then
115
+ val features = ctx.settings.language.value.filter(_.contains(nme.experimental.toString))
116
+ if features.nonEmpty then
117
+ report.error(
118
+ experimentalWarningMessage +
119
+ " \n The experimental language features are enabled via -language " + features.mkString(" ," )
120
+ )
121
+
99
122
end Feature
0 commit comments