@@ -47,13 +47,10 @@ object Typer {
47
47
/** The precedence of bindings which determines which of several bindings will be
48
48
* accessed by an Ident.
49
49
*/
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
57
54
}
58
55
59
56
/** Assert tree has a position, unless it is empty or a typed splice */
@@ -149,7 +146,7 @@ class Typer extends Namer
149
146
* @param prevCtx The context of the previous denotation,
150
147
* or else `NoContext` if nothing was found yet.
151
148
*/
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 = {
153
150
import BindingPrec ._
154
151
155
152
/** Check that any previously found result from an inner context
@@ -161,11 +158,11 @@ class Typer extends Namer
161
158
* previous and new contexts do not have the same scope, we select
162
159
* the previous (inner) definition. This models what scalac does.
163
160
*/
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 =
165
162
if (! previous.exists || ctx.typeComparer.isSameRef(previous, found)) found
166
163
else if ((prevCtx.scope eq ctx.scope) &&
167
- (newPrec == definition ||
168
- newPrec == namedImport && prevPrec == wildImport )) {
164
+ (newPrec == Definition ||
165
+ newPrec == NamedImport && prevPrec == WildImport )) {
169
166
// special cases: definitions beat imports, and named imports beat
170
167
// wildcard imports, provided both are in contexts with same scope
171
168
found
@@ -252,9 +249,9 @@ class Typer extends Namer
252
249
}
253
250
254
251
/** 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 ) =
256
253
! noImports &&
257
- (prevPrec < prec || prevPrec == prec && (prevCtx.scope eq ctx.scope))
254
+ (prevPrec.ordinal < prec.ordinal || prevPrec == prec && (prevCtx.scope eq ctx.scope))
258
255
259
256
@ tailrec def loop (lastCtx : Context )(implicit ctx : Context ): Type = {
260
257
if (ctx.scope == null ) previous
@@ -309,14 +306,14 @@ class Typer extends Namer
309
306
effectiveOwner.thisType.select(name, defDenot)
310
307
}
311
308
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
313
310
else {
314
311
if (ctx.scala2Mode && ! foundUnderScala2.exists)
315
- foundUnderScala2 = checkNewOrShadowed(found, definition , scala2pkg = true )
312
+ foundUnderScala2 = checkNewOrShadowed(found, Definition , scala2pkg = true )
316
313
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)
320
317
}
321
318
}
322
319
}
@@ -329,14 +326,14 @@ class Typer extends Namer
329
326
if (curImport.unimported.exists) unimported += curImport.unimported
330
327
if (ctx.owner.is(Package ) && curImport != null && curImport.isRootImport && previous.exists)
331
328
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)) {
333
330
val namedImp = namedImportRef(curImport)
334
331
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) {
337
334
val wildImp = wildImportRef(curImport)
338
335
if (wildImp.exists)
339
- findRefRecur(checkNewOrShadowed(wildImp, wildImport ), wildImport , ctx)(outer)
336
+ findRefRecur(checkNewOrShadowed(wildImp, WildImport ), WildImport , ctx)(outer)
340
337
else {
341
338
updateUnimported()
342
339
loop(ctx)(outer)
@@ -356,7 +353,7 @@ class Typer extends Namer
356
353
loop(NoContext )(ctx)
357
354
}
358
355
359
- findRefRecur(NoType , BindingPrec .nothingBound , NoContext )
356
+ findRefRecur(NoType , BindingPrec .NothingBound , NoContext )
360
357
}
361
358
362
359
/** Attribute an identifier consisting of a simple name or wildcard
0 commit comments