@@ -41,7 +41,10 @@ object ContextOps:
41
41
else pre.findMember(name, pre, required, excluded)
42
42
}
43
43
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)
45
48
else
46
49
ctx.scope.denotsNamed(name).filterWithFlags(required, excluded).toDenot(NoPrefix )
47
50
}
@@ -55,11 +58,20 @@ object ContextOps:
55
58
final def javaFindMember (name : Name , pre : Type , lookInCompanion : Boolean , required : FlagSet = EmptyFlags , excluded : FlagSet = EmptyFlags ): Denotation =
56
59
assert(ctx.isJava)
57
60
inContext(ctx) {
58
-
61
+ import dotty . tools . dotc . core . NameOps . *
59
62
val preSym = pre.typeSymbol
60
-
61
63
// 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
63
75
64
76
// 2. Try to search in companion class if current is an object.
65
77
def searchCompanionClass = if lookInCompanion && preSym.is(Flags .Module ) then
0 commit comments