@@ -5391,12 +5391,31 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
53915391 if (isStableContext(tree, mode, pt)) tree setType clazz.thisType else tree
53925392 }
53935393
5394-
53955394 // For Java, instance and static members are in the same scope, but we put the static ones in the companion object
53965395 // so, when we can't find a member in the class scope, check the companion
53975396 def inCompanionForJavaStatic (cls : Symbol , name : Name ): Symbol =
53985397 if (! (context.unit.isJava && cls.isClass)) NoSymbol
53995398 else context.javaFindMember(cls.typeOfThis, name, s => s.isStaticMember || s.isStaticModule)._2
5399+ // For Java, a selection p.q requires checking if p is a type with member q; otherwise it is a package.
5400+ // If a non-package term was found, look for a class; otherwise just look for a package.
5401+ def repairJavaSelection (qual : Tree , name : Name ): Symbol =
5402+ if (! context.unit.isJava || ! qual.hasAttachment[RootSelection .type ] || qual.symbol.hasPackageFlag) NoSymbol
5403+ else qual match {
5404+ case Ident (qname) =>
5405+ val found =
5406+ if (qual.symbol.isTerm) {
5407+ val lookup = context.lookupSymbol(qname.toTypeName, s => qualifies(s) && s.isClass)
5408+ if (lookup.isSuccess) inCompanionForJavaStatic(lookup.symbol, name) else NoSymbol
5409+ }
5410+ else NoSymbol
5411+ found.orElse {
5412+ context.lookupSymbol(qname, s => qualifies(s) && s.hasPackageFlag) match {
5413+ case LookupSucceeded (_, pkg) => member(pkg.info, name)
5414+ case _ => NoSymbol
5415+ }
5416+ }
5417+ case _ => NoSymbol
5418+ }
54005419
54015420 // If they try C.tupled, make it (C.apply _).tupled
54025421 def fixUpCaseTupled (tree : Tree , qual : Tree , name : Name , mode : Mode ): Tree =
@@ -5435,7 +5454,10 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
54355454 if (! isPastTyper && isUniversalMember(result.symbol))
54365455 context.warning(tree.pos, s " dubious usage of ${result.symbol} with unit value " , WarningCategory .LintUniversalMethods )
54375456
5438- val sym = tree.symbol orElse member(qualTp, name) orElse inCompanionForJavaStatic(qualTp.typeSymbol, name)
5457+ val sym = tree.symbol
5458+ .orElse(member(qualTp, name))
5459+ .orElse(inCompanionForJavaStatic(qualTp.typeSymbol, name))
5460+ .orElse(repairJavaSelection(qual, name))
54395461 if ((sym eq NoSymbol ) && name != nme.CONSTRUCTOR && mode.inAny(EXPRmode | PATTERNmode )) {
54405462 // symbol not found? --> try to convert implicitly to a type that does have the required
54415463 // member. Added `| PATTERNmode` to allow enrichment in patterns (so we can add e.g., an
@@ -5655,7 +5677,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
56555677 startContext.lookupSymbol(name.toTypeName, qualifies).symbol
56565678 } else NoSymbol
56575679
5658- // in Java, only pick a package if it is rooted
5680+ // in Java, only pick a package p if it is rooted (no relative packaging)
56595681 def termQualifies (sym : Symbol ) = qualifies(sym) && (
56605682 ! startContext.unit.isJava || ! sym.hasPackageFlag
56615683 || sym.owner.isEffectiveRoot || sym.owner.isRootPackage || sym.isRootPackage
0 commit comments