From 58e5251dcb58ff2c4bb422ab9c3299fbdedb35e3 Mon Sep 17 00:00:00 2001 From: Georgi Krastev Date: Tue, 10 Dec 2019 01:52:11 +0100 Subject: [PATCH] Remove variance check for escaping locals --- .../tools/nsc/typechecker/RefChecks.scala | 2 -- .../scala/reflect/internal/Variances.scala | 19 +++---------------- 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala index 10252b633b34..0d35ae009c13 100644 --- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala +++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala @@ -1566,8 +1566,6 @@ abstract class RefChecks extends Transform { if (!sym.exists) devWarning("Select node has NoSymbol! " + tree + " / " + tree.tpe) - else if (sym.isLocalToThis) - varianceValidator.checkForEscape(sym, currentClass) def checkSuper(mix: Name) = // term should have been eliminated by super accessors diff --git a/src/reflect/scala/reflect/internal/Variances.scala b/src/reflect/scala/reflect/internal/Variances.scala index d0327d0f193c..6e6812c85db1 100644 --- a/src/reflect/scala/reflect/internal/Variances.scala +++ b/src/reflect/scala/reflect/internal/Variances.scala @@ -28,7 +28,6 @@ trait Variances { * TODO - eliminate duplication with varianceInType */ class VarianceValidator extends InternalTraverser { - private[this] val escapedLocals = mutable.HashSet[Symbol]() // A flag for when we're in a refinement, meaning method parameter types // need to be checked. private[this] var inRefinement = false @@ -38,17 +37,6 @@ trait Variances { try body finally inRefinement = saved } - /** Is every symbol in the owner chain between `site` and the owner of `sym` - * either a term symbol or private[this]? If not, add `sym` to the set of - * escaped locals. - * @pre sym.isLocalToThis - */ - @tailrec final def checkForEscape(sym: Symbol, site: Symbol): Unit = { - if (site == sym.owner || site == sym.owner.moduleClass || site.hasPackageFlag) () // done - else if (site.isTerm || site.isPrivateLocal) checkForEscape(sym, site.owner) // ok - recurse to owner - else escapedLocals += sym - } - protected def issueVarianceError(base: Symbol, sym: Symbol, required: Variance, tpe: Type): Unit = () // Flip occurrences of type parameters and parameters, unless @@ -62,10 +50,9 @@ trait Variances { ) // Is `sym` is local to a term or is private[this] or protected[this]? - def isExemptFromVariance(sym: Symbol): Boolean = !sym.owner.isClass || ( - (sym.isLocalToThis || sym.isSuperAccessor) // super accessors are implicitly local #4345 - && !escapedLocals(sym) - ) + def isExemptFromVariance(sym: Symbol): Boolean = + // super accessors are implicitly local #4345 + !sym.owner.isClass || sym.isLocalToThis || sym.isSuperAccessor private object ValidateVarianceMap extends VariancedTypeMap { private[this] var base: Symbol = _