Skip to content

Commit fd27202

Browse files
committed
Put erased under -Yerased-terms flag
`erased` will not be included in Scala 3.0 but could be added in future version. This feature will only be available with `-Yerased-terms`.
1 parent 1c713ad commit fd27202

File tree

141 files changed

+18
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

141 files changed

+18
-3
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ class ScalaSettings extends Settings.SettingGroup {
166166
// Extremely experimental language features
167167
val YnoKindPolymorphism: Setting[Boolean] = BooleanSetting("-Yno-kind-polymorphism", "Enable kind polymorphism (see https://dotty.epfl.ch/docs/reference/kind-polymorphism.html). Potentially unsound.")
168168
val YexplicitNulls: Setting[Boolean] = BooleanSetting("-Yexplicit-nulls", "Make reference types non-nullable. Nullable types can be expressed with unions: e.g. String|Null.")
169+
val YerasedTerms: Setting[Boolean] = BooleanSetting("-Yerased-terms", "Allows the use of erased terms.")
169170

170171
/** Area-specific debug output */
171172
val YexplainLowlevel: Setting[Boolean] = BooleanSetting("-Yexplain-lowlevel", "When explaining type errors, show types at a lower level.")

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ class Definitions {
221221
@tu lazy val ScalaXmlPackageClass: Symbol = ctx.getPackageClassIfDefined("scala.xml")
222222

223223
@tu lazy val CompiletimePackageObject: Symbol = ctx.requiredModule("scala.compiletime.package")
224+
@tu lazy val Compiletime_erasedValue : Symbol = CompiletimePackageObject.requiredMethod("erasedValue")
224225
@tu lazy val Compiletime_error : Symbol = CompiletimePackageObject.requiredMethod(nme.error)
225226
@tu lazy val Compiletime_constValue : Symbol = CompiletimePackageObject.requiredMethod("constValue")
226227
@tu lazy val Compiletime_constValueOpt: Symbol = CompiletimePackageObject.requiredMethod("constValueOpt")

compiler/src/dotty/tools/dotc/typer/Checking.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,8 @@ object Checking {
457457
sym.setFlag(Private) // break the overriding relationship by making sym Private
458458
}
459459
if (sym.is(Erased))
460-
checkApplicable(Erased, !sym.isOneOf(MutableOrLazy))
460+
if ctx.settings.YerasedTerms.value then checkApplicable(Erased, !sym.isOneOf(MutableOrLazy))
461+
else fail("cannot use `erased` without " + ctx.settings.YerasedTerms.name)
461462
}
462463

463464
/** Check the type signature of the symbol `M` defined by `tree` does not refer

compiler/src/dotty/tools/dotc/typer/Inliner.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,12 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
10251025
case Nil => (bbuf.toList, from, to)
10261026
}
10271027

1028-
if (!isImplicit) caseBindingMap += ((NoSymbol, scrutineeBinding))
1028+
scrutinee match {
1029+
case TypeApply(ev, _) if scrutinee.symbol != defn.Compiletime_erasedValue =>
1030+
// Erase `erasedValue` scrutinee
1031+
case _ =>
1032+
if (!isImplicit) caseBindingMap += ((NoSymbol, scrutineeBinding))
1033+
}
10291034
val gadtCtx = ctx.fresh.setFreshGADTBounds.addMode(Mode.GadtConstraintInference)
10301035
if (reducePattern(caseBindingMap, scrutineeSym.termRef, cdef.pat)(gadtCtx)) {
10311036
val (caseBindings, from, to) = substBindings(caseBindingMap.toList, mutable.ListBuffer(), Nil, Nil)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ class BootstrappedOnlyCompilationTests extends ParallelTesting {
118118
aggregateTests(
119119
compileFilesInDir("tests/run-macros", defaultOptions),
120120
compileFilesInDir("tests/run-custom-args/Yretain-trees", defaultOptions and "-Yretain-trees"),
121+
compileFilesInDir("tests/run-custom-args/Yerased-terms", defaultOptions and "-Yerased-terms"),
121122
)
122123
}.checkRuns()
123124

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class CompilationTests extends ParallelTesting {
4747
compileFilesInDir("tests/pos-special/isInstanceOf", allowDeepSubtypes.and("-Xfatal-warnings")),
4848
compileFilesInDir("tests/new", defaultOptions),
4949
compileFilesInDir("tests/pos-scala2", scala2CompatMode),
50+
compileFilesInDir("tests/pos-custom-args/erased", defaultOptions.and("-Yerased-terms")),
5051
compileFilesInDir("tests/pos", defaultOptions),
5152
compileFilesInDir("tests/pos-deep-subtype", allowDeepSubtypes),
5253
compileFile(
@@ -114,6 +115,7 @@ class CompilationTests extends ParallelTesting {
114115
compileFilesInDir("tests/neg-no-kind-polymorphism", defaultOptions and "-Yno-kind-polymorphism"),
115116
compileFilesInDir("tests/neg-custom-args/deprecation", defaultOptions.and("-Xfatal-warnings", "-deprecation")),
116117
compileFilesInDir("tests/neg-custom-args/fatal-warnings", defaultOptions.and("-Xfatal-warnings")),
118+
compileFilesInDir("tests/neg-custom-args/erased", defaultOptions.and("-Yerased-terms")),
117119
compileFilesInDir("tests/neg-custom-args/allow-double-bindings", allowDoubleBindings),
118120
compileFilesInDir("tests/neg-custom-args/explicit-nulls", defaultOptions.and("-Yexplicit-nulls")),
119121
compileDir("tests/neg-custom-args/impl-conv", defaultOptions.and("-Xfatal-warnings", "-feature")),
@@ -165,6 +167,7 @@ class CompilationTests extends ParallelTesting {
165167
compileFile("tests/run-custom-args/i5256.scala", allowDeepSubtypes),
166168
compileFile("tests/run-custom-args/fors.scala", defaultOptions and "-strict"),
167169
compileFile("tests/run-custom-args/no-useless-forwarders.scala", defaultOptions and "-Xmixin-force-forwarders:false"),
170+
compileFilesInDir("tests/run-custom-args/erased", defaultOptions.and("-Yerased-terms")),
168171
compileFilesInDir("tests/run-deep-subtype", allowDeepSubtypes),
169172
compileFilesInDir("tests/run", defaultOptions)
170173
).checkRuns()

library/src/scala/compiletime/package.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package scala
22

3+
import scala.annotation.compileTimeOnly
4+
35
package object compiletime {
46

5-
erased def erasedValue[T]: T = ???
7+
@compileTimeOnly("`erasedValue` should have been evaluated away by `inline match`")
8+
/*erased*/ def erasedValue[T]: T = ???
69

710
/** The error method is used to produce user-defined compile errors during inline expansion.
811
* If an inline expansion results in a call error(msgStr) the compiler produces an error message containing the given msgStr.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)