@@ -41,7 +41,10 @@ object ContextOps:
4141 else pre.findMember(name, pre, required, excluded)
4242 }
4343 else // we are in the outermost context belonging to a class; self is invisible here. See inClassContext.
44- ctx.owner.findMember(name, ctx.owner.thisType, required, excluded)
44+ if ctx.isJava then
45+ javaFindMember(name, ctx.owner.thisType, lookInCompanion = true ,required, excluded)
46+ else
47+ ctx.owner.findMember(name, ctx.owner.thisType, required, excluded)
4548 else
4649 ctx.scope.denotsNamed(name).filterWithFlags(required, excluded).toDenot(NoPrefix )
4750 }
@@ -55,11 +58,20 @@ object ContextOps:
5558 final def javaFindMember (name : Name , pre : Type , lookInCompanion : Boolean , required : FlagSet = EmptyFlags , excluded : FlagSet = EmptyFlags ): Denotation =
5659 assert(ctx.isJava)
5760 inContext(ctx) {
58-
61+ import dotty . tools . dotc . core . NameOps . *
5962 val preSym = pre.typeSymbol
60-
6163 // 1. Try to search in current type and parents.
62- val directSearch = pre.findMember(name, pre, required, excluded)
64+ val directSearch =
65+ def asModule =
66+ if name.isTypeName && name.endsWith(StdNames .str.MODULE_SUFFIX ) then
67+ pre.findMember(name.stripModuleClassSuffix.moduleClassName, pre, required, excluded) match
68+ case NoDenotation => NoDenotation
69+ case symDenot : SymDenotation =>
70+ symDenot.companionModule.denot
71+ else NoDenotation
72+ pre.findMember(name, pre, required, excluded) match
73+ case NoDenotation => asModule
74+ case denot => denot
6375
6476 // 2. Try to search in companion class if current is an object.
6577 def searchCompanionClass = if lookInCompanion && preSym.is(Flags .Module ) then
0 commit comments