Skip to content

Commit b9d4893

Browse files
Refactor abstraction over language.feature module
All the deleted code was used to distinguish between scala.language.feature and dotty.language.feature, but the latter got removed with the introduction of the scalaShadowing package and has been dead code since then.
1 parent 7e26ac3 commit b9d4893

File tree

8 files changed

+28
-35
lines changed

8 files changed

+28
-35
lines changed

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

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -379,29 +379,24 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
379379
* where <prefix> is the full name of the owner followed by a "." minus
380380
* the prefix "dotty.language.".
381381
*/
382-
def featureEnabled(owner: ClassSymbol, feature: TermName): Boolean = {
383-
val hasImport =
382+
def featureEnabled(feature: TermName): Boolean = {
383+
def hasImport =
384384
ctx.importInfo != null &&
385-
ctx.importInfo.featureImported(owner, feature)(ctx.withPhase(ctx.typerPhase))
386-
def hasOption = {
387-
def toPrefix(sym: Symbol): String =
388-
if (!sym.exists || (sym eq defn.LanguageModuleClass)) ""
389-
else toPrefix(sym.owner) + sym.name + "."
390-
val featureName = toPrefix(owner) + feature
391-
ctx.base.settings.language.value exists (s => s == featureName || s == "_")
392-
}
393-
hasImport || hasOption
385+
ctx.importInfo.featureImported(feature)(ctx.withPhase(ctx.typerPhase))
386+
val hasOption =
387+
ctx.base.settings.language.value.exists(s => s == feature.toString || s == "_")
388+
hasOption || hasImport
394389
}
395390

396391
/** Is auto-tupling enabled? */
397392
def canAutoTuple: Boolean =
398-
!featureEnabled(defn.LanguageModuleClass, nme.noAutoTupling)
393+
!featureEnabled(nme.noAutoTupling)
399394

400395
def scala2Mode: Boolean =
401-
featureEnabled(defn.LanguageModuleClass, nme.Scala2)
396+
featureEnabled(nme.Scala2)
402397

403398
def dynamicsEnabled: Boolean =
404-
featureEnabled(defn.LanguageModuleClass, nme.dynamics)
399+
featureEnabled(nme.dynamics)
405400

406401
def testScala2Mode(msg: => Message, pos: SourcePosition, replace: => Unit = ()): Boolean = {
407402
if (scala2Mode) {
@@ -414,7 +409,8 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
414409
/** Is option -language:Scala2 set?
415410
* This test is used when we are too early in the pipeline to consider imports.
416411
*/
417-
def scala2Setting = ctx.settings.language.value.contains(nme.Scala2.toString)
412+
def scala2Setting: Boolean =
413+
ctx.settings.language.value.contains(nme.Scala2.toString)
418414

419415
/** Refine child based on parent
420416
*

compiler/src/dotty/tools/dotc/reporting/Reporter.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,10 @@ trait Reporting { this: Context =>
6666
def featureWarning(msg: => Message, pos: SourcePosition = NoSourcePosition): Unit =
6767
reportWarning(new FeatureWarning(msg, pos))
6868

69-
def featureWarning(feature: String, featureDescription: String, isScala2Feature: Boolean,
69+
def featureWarning(feature: String, featureDescription: String,
7070
featureUseSite: Symbol, required: Boolean, pos: SourcePosition): Unit = {
7171
val req = if (required) "needs to" else "should"
72-
val prefix = if (isScala2Feature) "scala." else "dotty."
73-
val fqname = prefix + "language." + feature
72+
val fqname = s"scala.language.$feature"
7473

7574
val explain = {
7675
if (reporter.isReportedFeatureUseSite(featureUseSite)) ""

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ trait Checking {
617617
def checkImplicitConversionDefOK(sym: Symbol)(implicit ctx: Context): Unit = {
618618
def check(): Unit = {
619619
checkFeature(
620-
defn.LanguageModuleClass, nme.implicitConversions,
620+
nme.implicitConversions,
621621
i"Definition of implicit conversion $sym",
622622
ctx.owner.topLevelClass,
623623
sym.sourcePos)
@@ -654,20 +654,17 @@ trait Checking {
654654
defn.isPredefClass(conv.owner) ||
655655
conv.name == nme.reflectiveSelectable && conv.maybeOwner.maybeOwner.maybeOwner == defn.ScalaPackageClass
656656
if (!conversionOK)
657-
checkFeature(defn.LanguageModuleClass, nme.implicitConversions,
657+
checkFeature(nme.implicitConversions,
658658
i"Use of implicit conversion ${conv.showLocated}", NoSymbol, posd.sourcePos)
659659
}
660660

661661
/** Issue a feature warning if feature is not enabled */
662-
def checkFeature(base: ClassSymbol,
663-
name: TermName,
662+
def checkFeature(name: TermName,
664663
description: => String,
665664
featureUseSite: Symbol,
666665
pos: SourcePosition)(implicit ctx: Context): Unit =
667-
if (!ctx.featureEnabled(base, name))
668-
ctx.featureWarning(name.toString, description,
669-
isScala2Feature = base.isContainedIn(defn.LanguageModuleClass),
670-
featureUseSite, required = false, pos)
666+
if (!ctx.featureEnabled(name))
667+
ctx.featureWarning(name.toString, description, featureUseSite, required = false, pos)
671668

672669
/** Check that `tp` is a class type and that any top-level type arguments in this type
673670
* are feasible, i.e. that their lower bound conforms to their upper bound. If a type
@@ -1048,5 +1045,5 @@ trait NoChecking extends ReChecking {
10481045
override def checkNoForwardDependencies(vparams: List[ValDef])(implicit ctx: Context): Unit = ()
10491046
override def checkMembersOK(tp: Type, pos: SourcePosition)(implicit ctx: Context): Type = tp
10501047
override def checkInInlineContext(what: String, posd: Positioned)(implicit ctx: Context): Unit = ()
1051-
override def checkFeature(base: ClassSymbol, name: TermName, description: => String, featureUseSite: Symbol, pos: SourcePosition)(implicit ctx: Context): Unit = ()
1048+
override def checkFeature(name: TermName, description: => String, featureUseSite: Symbol, pos: SourcePosition)(implicit ctx: Context): Unit = ()
10521049
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,7 @@ trait Implicits { self: Typer =>
947947

948948
private def strictEquality(implicit ctx: Context): Boolean =
949949
ctx.mode.is(Mode.StrictEquality) ||
950-
ctx.featureEnabled(defn.LanguageModuleClass, nme.strictEquality)
950+
ctx.featureEnabled(nme.strictEquality)
951951

952952
/** An Eql[T, U] instance is assumed
953953
* - if one of T, U is an error type, or

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,16 @@ class ImportInfo(symf: Context => Symbol, val selectors: List[untpd.Tree],
146146
private[this] var myUnimported: Symbol = _
147147

148148
/** Does this import clause or a preceding import clause import `owner.feature`? */
149-
def featureImported(owner: Symbol, feature: TermName)(implicit ctx: Context): Boolean = {
149+
def featureImported(feature: TermName)(implicit ctx: Context): Boolean = {
150+
val owner: Symbol = defn.LanguageModuleClass
150151
def compute = {
151152
val isImportOwner = site.widen.typeSymbol `eq` owner
152153
if (isImportOwner && originals.contains(feature)) true
153154
else if (isImportOwner && excluded.contains(feature)) false
154155
else {
155156
var c = ctx.outer
156157
while (c.importInfo eq ctx.importInfo) c = c.outer
157-
(c.importInfo != null) && c.importInfo.featureImported(owner, feature)(c)
158+
(c.importInfo != null) && c.importInfo.featureImported(feature)(c)
158159
}
159160
}
160161
if (lastOwner.ne(owner) || !lastResults.contains(feature)) {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,8 +1692,7 @@ class Typer extends Namer
16921692
!ctx.dynamicsEnabled
16931693
if (reportDynamicInheritance) {
16941694
val isRequired = parents1.exists(_.tpe.isRef(defn.DynamicClass))
1695-
ctx.featureWarning(nme.dynamics.toString, "extension of type scala.Dynamic", isScala2Feature = true,
1696-
cls, isRequired, cdef.sourcePos)
1695+
ctx.featureWarning(nme.dynamics.toString, "extension of type scala.Dynamic", cls, isRequired, cdef.sourcePos)
16971696
}
16981697

16991698
checkNonCyclicInherited(cls.thisType, cls.classParents, cls.info.decls, cdef.posd)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ class CompilationTests extends ParallelTesting {
3131

3232
// Positive tests ------------------------------------------------------------
3333

34-
// @Test // enable to test compileStdLib separately with detailed stats
34+
@Test // enable to test compileStdLib separately with detailed stats
3535
def compileStdLibOnly: Unit = {
3636
implicit val testGroup: TestGroup = TestGroup("compileStdLibOnly")
37-
compileList("compileStdLib", TestSources.stdLibSources, scala2Mode.and("-migration", "-Yno-inline", "-Ydetailed-stats"))
37+
compileList("compileStdLib", TestSources.stdLibSources, scala2Mode.and("-migration", "-Yno-inline"))
3838
}.checkCompile()
3939

4040
@Test def pos: Unit = {

library/src/scalaShadowing/language.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ package scalaShadowing
3030
*
3131
* - [[Scala2 `Scala2`] backwards compatibility mode for Scala2
3232
* - [[noAtoTupling `noAutoTupling`]] disable auto-tupling
33+
* - [[strictEquality `strictEquality`]] enable strick equality
3334
*
3435
* @groupname production Language Features
3536
* @groupname experimental Experimental Language Features
@@ -217,6 +218,6 @@ object language {
217218
/** Where imported, auto-tupling is disabled */
218219
object noAutoTupling
219220

220-
/* Where imported loose equality using eqAny is disabled */
221+
/** Where imported loose equality using eqAny is disabled */
221222
object strictEquality
222223
}

0 commit comments

Comments
 (0)