@@ -47,13 +47,10 @@ object Typer {
4747 /** The precedence of bindings which determines which of several bindings will be
4848 * accessed by an Ident.
4949 */
50- object BindingPrec {
51- val definition : Int = 4
52- val namedImport : Int = 3
53- val wildImport : Int = 2
54- val packageClause : Int = 1
55- val nothingBound : Int = 0
56- def isImportPrec (prec : Int ): Boolean = prec == namedImport || prec == wildImport
50+ enum BindingPrec {
51+ case NothingBound , PackageClause , WildImport , NamedImport , Definition
52+
53+ def isImportPrec = this == NamedImport || this == WildImport
5754 }
5855
5956 /** Assert tree has a position, unless it is empty or a typed splice */
@@ -149,7 +146,7 @@ class Typer extends Namer
149146 * @param prevCtx The context of the previous denotation,
150147 * or else `NoContext` if nothing was found yet.
151148 */
152- def findRefRecur (previous : Type , prevPrec : Int , prevCtx : Context )(implicit ctx : Context ): Type = {
149+ def findRefRecur (previous : Type , prevPrec : BindingPrec , prevCtx : Context )(implicit ctx : Context ): Type = {
153150 import BindingPrec ._
154151
155152 /** Check that any previously found result from an inner context
@@ -161,11 +158,11 @@ class Typer extends Namer
161158 * previous and new contexts do not have the same scope, we select
162159 * the previous (inner) definition. This models what scalac does.
163160 */
164- def checkNewOrShadowed (found : Type , newPrec : Int , scala2pkg : Boolean = false )(implicit ctx : Context ): Type =
161+ def checkNewOrShadowed (found : Type , newPrec : BindingPrec , scala2pkg : Boolean = false )(implicit ctx : Context ): Type =
165162 if (! previous.exists || ctx.typeComparer.isSameRef(previous, found)) found
166163 else if ((prevCtx.scope eq ctx.scope) &&
167- (newPrec == definition ||
168- newPrec == namedImport && prevPrec == wildImport )) {
164+ (newPrec == Definition ||
165+ newPrec == NamedImport && prevPrec == WildImport )) {
169166 // special cases: definitions beat imports, and named imports beat
170167 // wildcard imports, provided both are in contexts with same scope
171168 found
@@ -252,9 +249,9 @@ class Typer extends Namer
252249 }
253250
254251 /** Would import of kind `prec` be not shadowed by a nested higher-precedence definition? */
255- def isPossibleImport (prec : Int )(implicit ctx : Context ) =
252+ def isPossibleImport (prec : BindingPrec )(implicit ctx : Context ) =
256253 ! noImports &&
257- (prevPrec < prec || prevPrec == prec && (prevCtx.scope eq ctx.scope))
254+ (prevPrec.ordinal < prec.ordinal || prevPrec == prec && (prevCtx.scope eq ctx.scope))
258255
259256 @ tailrec def loop (lastCtx : Context )(implicit ctx : Context ): Type = {
260257 if (ctx.scope == null ) previous
@@ -309,14 +306,14 @@ class Typer extends Namer
309306 effectiveOwner.thisType.select(name, defDenot)
310307 }
311308 if (! curOwner.is(Package ) || isDefinedInCurrentUnit(defDenot))
312- result = checkNewOrShadowed(found, definition ) // no need to go further out, we found highest prec entry
309+ result = checkNewOrShadowed(found, Definition ) // no need to go further out, we found highest prec entry
313310 else {
314311 if (ctx.scala2Mode && ! foundUnderScala2.exists)
315- foundUnderScala2 = checkNewOrShadowed(found, definition , scala2pkg = true )
312+ foundUnderScala2 = checkNewOrShadowed(found, Definition , scala2pkg = true )
316313 if (defDenot.symbol.is(Package ))
317- result = checkNewOrShadowed(previous orElse found, packageClause )
318- else if (prevPrec < packageClause )
319- result = findRefRecur(found, packageClause , ctx)(ctx.outer)
314+ result = checkNewOrShadowed(previous orElse found, PackageClause )
315+ else if (prevPrec.ordinal < PackageClause .ordinal )
316+ result = findRefRecur(found, PackageClause , ctx)(ctx.outer)
320317 }
321318 }
322319 }
@@ -329,14 +326,14 @@ class Typer extends Namer
329326 if (curImport.unimported.exists) unimported += curImport.unimported
330327 if (ctx.owner.is(Package ) && curImport != null && curImport.isRootImport && previous.exists)
331328 previous // no more conflicts possible in this case
332- else if (isPossibleImport(namedImport ) && (curImport ne outer.importInfo)) {
329+ else if (isPossibleImport(NamedImport ) && (curImport ne outer.importInfo)) {
333330 val namedImp = namedImportRef(curImport)
334331 if (namedImp.exists)
335- findRefRecur(checkNewOrShadowed(namedImp, namedImport ), namedImport , ctx)(outer)
336- else if (isPossibleImport(wildImport ) && ! curImport.sym.isCompleting) {
332+ findRefRecur(checkNewOrShadowed(namedImp, NamedImport ), NamedImport , ctx)(outer)
333+ else if (isPossibleImport(WildImport ) && ! curImport.sym.isCompleting) {
337334 val wildImp = wildImportRef(curImport)
338335 if (wildImp.exists)
339- findRefRecur(checkNewOrShadowed(wildImp, wildImport ), wildImport , ctx)(outer)
336+ findRefRecur(checkNewOrShadowed(wildImp, WildImport ), WildImport , ctx)(outer)
340337 else {
341338 updateUnimported()
342339 loop(ctx)(outer)
@@ -356,7 +353,7 @@ class Typer extends Namer
356353 loop(NoContext )(ctx)
357354 }
358355
359- findRefRecur(NoType , BindingPrec .nothingBound , NoContext )
356+ findRefRecur(NoType , BindingPrec .NothingBound , NoContext )
360357 }
361358
362359 /** Attribute an identifier consisting of a simple name or wildcard
0 commit comments