Skip to content

Commit d201b5d

Browse files
authored
Merge pull request scala#5890 from som-snytt/issue/settings
Compute also isScala211 only once
2 parents 96d7e16 + bcb3418 commit d201b5d

File tree

3 files changed

+5
-12
lines changed

3 files changed

+5
-12
lines changed

src/compiler/scala/tools/nsc/settings/ScalaSettings.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ trait ScalaSettings extends AbsScalaSettings
8383
* The previous "-source" option is intended to be used mainly
8484
* though this helper.
8585
*/
86-
def isScala211: Boolean = source.value >= ScalaVersion("2.11.0")
86+
private[this] val version211 = ScalaVersion("2.11.0")
87+
def isScala211: Boolean = source.value >= version211
8788
private[this] val version212 = ScalaVersion("2.12.0")
8889
def isScala212: Boolean = source.value >= version212
8990
private[this] val version213 = ScalaVersion("2.13.0")

src/compiler/scala/tools/nsc/typechecker/Implicits.scala

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,9 +1424,9 @@ trait Implicits {
14241424
val outSym = out.typeSymbol
14251425

14261426
val fail =
1427-
if (out.annotations.isEmpty && (outSym == ObjectClass || (isScala211 && outSym == AnyValClass)))
1427+
if (out.annotations.isEmpty && (outSym == ObjectClass || (settings.isScala211 && outSym == AnyValClass)))
14281428
maybeInvalidConversionError(s"the result type of an implicit conversion must be more specific than $out")
1429-
else if (isScala211 && in.annotations.isEmpty && in.typeSymbol == NullClass)
1429+
else if (settings.isScala211 && in.annotations.isEmpty && in.typeSymbol == NullClass)
14301430
maybeInvalidConversionError("an expression of type Null is ineligible for implicit conversion")
14311431
else false
14321432

@@ -1442,9 +1442,6 @@ trait Implicits {
14421442
result
14431443
}
14441444

1445-
// this setting is expensive to check, actually....
1446-
private[this] val isScala211 = settings.isScala211
1447-
14481445
def allImplicits: List[SearchResult] = {
14491446
def search(iss: Infoss, isLocalToCallsite: Boolean) = applicableInfos(iss, isLocalToCallsite).values
14501447
(

src/compiler/scala/tools/nsc/typechecker/Namers.scala

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,6 @@ trait Namers extends MethodSynthesis {
5858
private lazy val innerNamer =
5959
if (isTemplateContext(context)) createInnerNamer() else this
6060

61-
// Cached as a val because `settings.isScala212` parses the Scala version each time...
62-
// Not in Namers because then we need to go to outer first to check this.
63-
// I do think it's ok to check every time we create a Namer instance (so, not a lazy val).
64-
private[this] val isScala212 = settings.isScala212
65-
6661
def createNamer(tree: Tree): Namer = {
6762
val sym = tree match {
6863
case ModuleDef(_, _, _) => tree.symbol.moduleClass
@@ -1586,7 +1581,7 @@ trait Namers extends MethodSynthesis {
15861581
val valOwner = owner.owner
15871582
// there's no overriding outside of classes, and we didn't use to do this in 2.11, so provide opt-out
15881583

1589-
if (!isScala212 || !valOwner.isClass) WildcardType
1584+
if (!settings.isScala212 || !valOwner.isClass) WildcardType
15901585
else {
15911586
// normalize to getter so that we correctly consider a val overriding a def
15921587
// (a val's name ends in a " ", so can't compare to def)

0 commit comments

Comments
 (0)