Skip to content

Commit

Permalink
Remove variance check for escaping locals
Browse files Browse the repository at this point in the history
  • Loading branch information
joroKr21 committed Dec 10, 2019
1 parent cab4555 commit 58e5251
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 18 deletions.
2 changes: 0 additions & 2 deletions src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
Expand Up @@ -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
Expand Down
19 changes: 3 additions & 16 deletions src/reflect/scala/reflect/internal/Variances.scala
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 = _
Expand Down

0 comments on commit 58e5251

Please sign in to comment.