Skip to content

Commit 0ff81d7

Browse files
Refactor useless abstraction over language.feature
All the deleted code was here to warn about importing scala.language.feature vs dotty.language.feature, but that was done before the scalaShadowing package trick has become dead code since then.
1 parent 6b709a6 commit 0ff81d7

File tree

6 files changed

+19
-28
lines changed

6 files changed

+19
-28
lines changed

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

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -379,26 +379,21 @@ 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 = {
382+
def featureEnabled(feature: TermName): Boolean = {
383383
val 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-
}
385+
ctx.importInfo.featureImported(feature)(ctx.withPhase(ctx.typerPhase))
386+
def hasOption =
387+
ctx.base.settings.language.value exists (s => s == feature.toString || s == "_")
393388
hasImport || hasOption
394389
}
395390

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

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

403398
def testScala2Mode(msg: => Message, pos: SourcePosition, replace: => Unit = ()): Boolean = {
404399
if (scala2Mode) {

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)

0 commit comments

Comments
 (0)