Skip to content

Commit 06106a7

Browse files
committed
Test with -Yno-experimental
1 parent 295d953 commit 06106a7

File tree

5 files changed

+36
-5
lines changed

5 files changed

+36
-5
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,12 @@ object Feature:
3131

3232
/** Experimental features are only enabled for snapshot and nightly compiler versions
3333
*/
34-
def checkExperimentalFeature(feature: TermName): Boolean =
34+
def experimentalEnabled(using Context): Boolean =
35+
Properties.experimental && !ctx.settings.YnoExperimental.value
36+
37+
def isExperimental(feature: TermName): Boolean =
3538
feature match
36-
case QualifiedName(nme.experimental, _) => Properties.experimental
39+
case QualifiedName(nme.experimental, _) => true
3740
case _ => true
3841

3942
/** Is `feature` enabled by by a command-line setting? The enabling setting is
@@ -68,7 +71,8 @@ object Feature:
6871
* Note: Experimental features are only enabled for snapshot and nightly version of compiler.
6972
*/
7073
def enabled(feature: TermName)(using Context): Boolean =
71-
checkExperimentalFeature(feature) && (enabledBySetting(feature) || enabledByImport(feature))
74+
(experimentalEnabled || !isExperimental(feature))
75+
&& (enabledBySetting(feature) || enabledByImport(feature))
7276

7377
/** Is auto-tupling enabled? */
7478
def autoTuplingEnabled(using Context): Boolean = !enabled(nme.noAutoTupling)
@@ -111,7 +115,7 @@ object Feature:
111115

112116
/** Check that experimental compiler options are only set for snapshot or nightly compiler versions. */
113117
def checkExperimentalFlags(using Context): Unit =
114-
if !Properties.experimental then
118+
if !experimentalEnabled then
115119
val features = ctx.settings.language.value.filter(_.contains(nme.experimental.toString))
116120
if features.nonEmpty then
117121
report.error(

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ class ScalaSettings extends Settings.SettingGroup with CommonScalaSettings {
215215
val YretainTrees: Setting[Boolean] = BooleanSetting("-Yretain-trees", "Retain trees for top-level classes, accessible from ClassSymbol#tree")
216216
val YshowTreeIds: Setting[Boolean] = BooleanSetting("-Yshow-tree-ids", "Uniquely tag all tree nodes in debugging output.")
217217
val YfromTastyIgnoreList: Setting[List[String]] = MultiStringSetting("-Yfrom-tasty-ignore-list", "file", "List of `tasty` files in jar files that will not be loaded when using -from-tasty")
218+
val YnoExperimental: Setting[Boolean] = BooleanSetting("-Yno-experimental", "Disable experimental language features")
218219

219220
val YprofileEnabled: Setting[Boolean] = BooleanSetting("-Yprofile-enabled", "Enable profiling.")
220221
val YprofileDestination: Setting[String] = StringSetting("-Yprofile-destination", "file", "Where to send profiling output - specify a file, default is to the console.", "")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3036,7 +3036,7 @@ object Parsers {
30363036
val imp = Import(tree, selectors)
30373037
if isLanguageImport(tree) then
30383038
in.languageImportContext = in.languageImportContext.importContext(imp, NoSymbol)
3039-
if isExperimentalImport(tree) && !Properties.experimental then
3039+
if isExperimentalImport(tree) && !Feature.experimentalEnabled then
30403040
report.error(Feature.experimentalWarningMessage, imp.srcPos)
30413041
for
30423042
case ImportSelector(id @ Ident(imported), EmptyTree, _) <- selectors

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ class CompilationTests {
130130
compileFilesInDir("tests/neg-custom-args/allow-double-bindings", allowDoubleBindings),
131131
compileFilesInDir("tests/neg-custom-args/allow-deep-subtypes", allowDeepSubtypes),
132132
compileFilesInDir("tests/neg-custom-args/explicit-nulls", defaultOptions.and("-Yexplicit-nulls")),
133+
compileFilesInDir("tests/neg-custom-args/no-experimental", defaultOptions.and("-Yno-experimental")),
133134
compileDir("tests/neg-custom-args/impl-conv", defaultOptions.and("-Xfatal-warnings", "-feature")),
134135
compileFile("tests/neg-custom-args/implicit-conversions.scala", defaultOptions.and("-Xfatal-warnings", "-feature")),
135136
compileFile("tests/neg-custom-args/implicit-conversions-old.scala", defaultOptions.and("-Xfatal-warnings", "-feature")),
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Test0 {
2+
import language.experimental.namedTypeArguments // error
3+
object Foo {
4+
inline def f[S, T](x: S): T = ???
5+
def g(x: Int) = f[T = Any](x) // error
6+
}
7+
}
8+
9+
class Test1 {
10+
import language.experimental.erasedDefinitions // error
11+
import scala.compiletime.erasedValue
12+
type UnivEq[A]
13+
object UnivEq:
14+
erased def force[A]: UnivEq[A] = erasedValue // error // error // error
15+
extension [A](erased proof: UnivEq[A]) // error
16+
inline def univEq(a: A, b: A): Boolean =
17+
a == b
18+
}
19+
20+
class Test1 {
21+
import language.experimental.genericNumberLiterals // error
22+
val x: BigInt = 13232202002020202020202
23+
val y: BigInt = -0xaabb12345ACF12345AC
24+
}
25+

0 commit comments

Comments
 (0)