From d8613df1cd6545f85767bf649a483621676b5893 Mon Sep 17 00:00:00 2001 From: Adriaan Moors Date: Wed, 22 Feb 2017 11:02:56 -0800 Subject: Create scope only once --- src/compiler/scala/tools/nsc/typechecker/Typers.scala | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 2cbd9475fc..1f2b8ae16e 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -3099,8 +3099,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper || (looker.hasAccessorFlag && !accessed.hasAccessorFlag && accessed.isPrivate) ) - def checkNoDoubleDefs: Unit = { - val scope = if (inBlock) context.scope else context.owner.info.decls + def checkNoDoubleDefs(scope: Scope): Unit = { var e = scope.elems while ((e ne null) && e.owner == scope) { var e1 = scope.lookupNextEntry(e) @@ -3143,8 +3142,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper } } - def addSynthetics(stats: List[Tree]): List[Tree] = { - val scope = if (inBlock) context.scope else context.owner.info.decls + def addSynthetics(stats: List[Tree], scope: Scope): List[Tree] = { var newStats = new ListBuffer[Tree] var moreToAdd = true while (moreToAdd) { @@ -3219,11 +3217,14 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper val stats1 = stats mapConserve typedStat if (phase.erasedTypes) stats1 else { + val scope = if (inBlock) context.scope else context.owner.info.decls + // As packages are open, it doesn't make sense to check double definitions here. Furthermore, // it is expensive if the package is large. Instead, such double definitions are checked in `Namers.enterInScope` if (!context.owner.isPackageClass) - checkNoDoubleDefs - addSynthetics(stats1) + checkNoDoubleDefs(scope) + + addSynthetics(stats1, scope) } } -- cgit v1.2.3