@@ -180,7 +180,7 @@ trait Contexts { self: Analyzer =>
180
180
scope : Scope , imports : List [ImportInfo ]): Context = {
181
181
val c = new Context
182
182
c.unit = unit
183
- c.tree = sanitize(tree)
183
+ c.tree = /* sanitize*/ (tree) // used to be for IDE
184
184
c.owner = owner
185
185
c.scope = scope
186
186
@@ -464,20 +464,35 @@ trait Contexts { self: Analyzer =>
464
464
implicitsCache = null
465
465
if (outer != null && outer != this ) outer.resetCache
466
466
}
467
- private def collectImplicits (syms : List [Symbol ], pre : Type ): List [ImplicitInfo ] =
468
- for (sym <- syms if sym.hasFlag(IMPLICIT ) && isAccessible(sym, pre, false ))
467
+
468
+ /** A symbol `sym` qualifies as an implicit if it has the IMPLICIT flag set,
469
+ * it is accessible, and if it is imported there is not already a local symbol
470
+ * with the same names. Local symbols override imported ones. This fixes #2866.
471
+ */
472
+ private def isQualifyingImplicit (sym : Symbol , pre : Type , imported : Boolean ) =
473
+ sym.hasFlag(IMPLICIT ) &&
474
+ isAccessible(sym, pre, false ) &&
475
+ ! (imported && {
476
+ val e = scope.lookupEntry(sym.name)
477
+ (e ne null ) && (e.owner == scope)
478
+ })
479
+
480
+ private def collectImplicits (syms : List [Symbol ], pre : Type , imported : Boolean = false ): List [ImplicitInfo ] =
481
+ for (sym <- syms if isQualifyingImplicit(sym, pre, imported))
469
482
yield new ImplicitInfo (sym.name, pre, sym)
470
483
471
484
private def collectImplicitImports (imp : ImportInfo ): List [ImplicitInfo ] = {
472
485
val pre = imp.qual.tpe
473
486
def collect (sels : List [ImportSelector ]): List [ImplicitInfo ] = sels match {
474
- case List () => List ()
475
- case List (ImportSelector (nme.WILDCARD , _, _, _)) => collectImplicits(pre.implicitMembers, pre)
487
+ case List () =>
488
+ List ()
489
+ case List (ImportSelector (nme.WILDCARD , _, _, _)) =>
490
+ collectImplicits(pre.implicitMembers, pre, imported = true )
476
491
case ImportSelector (from, _, to, _) :: sels1 =>
477
492
var impls = collect(sels1) filter (info => info.name != from)
478
493
if (to != nme.WILDCARD ) {
479
494
for (sym <- imp.importedSymbol(to).alternatives)
480
- if (sym.hasFlag( IMPLICIT ) && isAccessible( sym, pre, false ))
495
+ if (isQualifyingImplicit( sym, pre, imported = true ))
481
496
impls = new ImplicitInfo (to, pre, sym) :: impls
482
497
}
483
498
impls
@@ -488,7 +503,6 @@ trait Contexts { self: Analyzer =>
488
503
489
504
def implicitss : List [List [ImplicitInfo ]] = {
490
505
val nextOuter = if (owner.isConstructor) outer.outer.outer else outer
491
- // can we can do something smarter to bring back the implicit cache?
492
506
if (implicitsRunId != currentRunId) {
493
507
implicitsRunId = currentRunId
494
508
implicitsCache = List ()
@@ -545,7 +559,7 @@ trait Contexts { self: Analyzer =>
545
559
/** The prefix expression */
546
560
def qual : Tree = tree.symbol.info match {
547
561
case ImportType (expr) => expr
548
- case ErrorType => tree
562
+ case ErrorType => tree setType NoType // fix for #2870
549
563
case _ => throw new FatalError (" symbol " + tree.symbol + " has bad type: " + tree.symbol.info);// debug
550
564
}
551
565
@@ -561,16 +575,16 @@ trait Contexts { self: Analyzer =>
561
575
var renamed = false
562
576
var selectors = tree.selectors
563
577
while (selectors != Nil && result == NoSymbol ) {
564
- if (selectors.head.name != nme.WILDCARD )
565
- notifyImport(name, qual.tpe, selectors.head.name, selectors.head.rename)
578
+ // if (selectors.head.name != nme.WILDCARD) // used to be for IDE
579
+ // notifyImport(name, qual.tpe, selectors.head.name, selectors.head.rename)
566
580
567
581
if (selectors.head.rename == name.toTermName)
568
- result = qual.tpe.member(
582
+ result = qual.tpe.nonLocalMember( // new to address #2733: consider only non-local members for imports
569
583
if (name.isTypeName) selectors.head.name.toTypeName else selectors.head.name)
570
584
else if (selectors.head.name == name.toTermName)
571
585
renamed = true
572
586
else if (selectors.head.name == nme.WILDCARD && ! renamed)
573
- result = qual.tpe.member (name)
587
+ result = qual.tpe.nonLocalMember (name)
574
588
selectors = selectors.tail
575
589
}
576
590
result
0 commit comments