@@ -34,7 +34,10 @@ object ContextOps:
3434 if (elem.name == name) return elem.sym.denot // return self
3535 }
3636 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)
3841 else pre.findMember(name, pre, required, excluded)
3942 }
4043 else // we are in the outermost context belonging to a class; self is invisible here. See inClassContext.
@@ -43,7 +46,13 @@ object ContextOps:
4346 ctx.scope.denotsNamed(name).filterWithFlags(required, excluded).toDenot(NoPrefix )
4447 }
4548
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 =
4756 assert(ctx.isJava)
4857 inContext(ctx) {
4958
@@ -53,7 +62,7 @@ object ContextOps:
5362 val directSearch = pre.findMember(name, pre, required, excluded)
5463
5564 // 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
5766 preSym.companionClass.thisType.findMember(name, pre, required, excluded)
5867 else NoDenotation
5968
0 commit comments