@@ -34,7 +34,10 @@ object ContextOps:
34
34
if (elem.name == name) return elem.sym.denot // return self
35
35
}
36
36
val pre = ctx.owner.thisType
37
- if ctx.isJava then javaFindMember(name, pre, required, excluded)
37
+ if ctx.isJava then
38
+ // Note: I didn't verify if there exists a code path that would require `lookInCompanion = true`,
39
+ // it is just to preserve the original behavior.
40
+ javaFindMember(name, pre, lookInCompanion = true , required, excluded)
38
41
else pre.findMember(name, pre, required, excluded)
39
42
}
40
43
else // we are in the outermost context belonging to a class; self is invisible here. See inClassContext.
@@ -43,7 +46,13 @@ object ContextOps:
43
46
ctx.scope.denotsNamed(name).filterWithFlags(required, excluded).toDenot(NoPrefix )
44
47
}
45
48
46
- final def javaFindMember (name : Name , pre : Type , required : FlagSet = EmptyFlags , excluded : FlagSet = EmptyFlags ): Denotation =
49
+ /** Look in the prefix with Java semantics.
50
+ * @param lookInCompanion If true, try in the companion class of a module as a fallback.
51
+ * Note: originally this was used to type Select nodes in Java code,
52
+ * but that is no longer the case.
53
+ * It is preserved in case it is necessary for denotNamed, but this is unverified.
54
+ */
55
+ final def javaFindMember (name : Name , pre : Type , lookInCompanion : Boolean , required : FlagSet = EmptyFlags , excluded : FlagSet = EmptyFlags ): Denotation =
47
56
assert(ctx.isJava)
48
57
inContext(ctx) {
49
58
@@ -53,7 +62,7 @@ object ContextOps:
53
62
val directSearch = pre.findMember(name, pre, required, excluded)
54
63
55
64
// 2. Try to search in companion class if current is an object.
56
- def searchCompanionClass = if preSym.is(Flags .Module ) then
65
+ def searchCompanionClass = if lookInCompanion && preSym.is(Flags .Module ) then
57
66
preSym.companionClass.thisType.findMember(name, pre, required, excluded)
58
67
else NoDenotation
59
68
0 commit comments