Skip to content

Commit 9ba2eec

Browse files
committed
do not look in companion in javaFindMember in typedSelect
1 parent def38db commit 9ba2eec

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

compiler/src/dotty/tools/dotc/core/ContextOps.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ 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 javaFindMember(name, pre, lookInCompanion = true, required, excluded)
3838
else pre.findMember(name, pre, required, excluded)
3939
}
4040
else // we are in the outermost context belonging to a class; self is invisible here. See inClassContext.
@@ -43,7 +43,10 @@ object ContextOps:
4343
ctx.scope.denotsNamed(name).filterWithFlags(required, excluded).toDenot(NoPrefix)
4444
}
4545

46-
final def javaFindMember(name: Name, pre: Type, required: FlagSet = EmptyFlags, excluded: FlagSet = EmptyFlags): Denotation =
46+
/** Look in the prefix with Java semantics.
47+
* @param lookInCompanion If true, try in the companion class of a module as a fallback.
48+
*/
49+
final def javaFindMember(name: Name, pre: Type, lookInCompanion: Boolean, required: FlagSet = EmptyFlags, excluded: FlagSet = EmptyFlags): Denotation =
4750
assert(ctx.isJava)
4851
inContext(ctx) {
4952

@@ -53,7 +56,7 @@ object ContextOps:
5356
val directSearch = pre.findMember(name, pre, required, excluded)
5457

5558
// 2. Try to search in companion class if current is an object.
56-
def searchCompanionClass = if preSym.is(Flags.Module) then
59+
def searchCompanionClass = if lookInCompanion && preSym.is(Flags.Module) then
5760
preSym.companionClass.thisType.findMember(name, pre, required, excluded)
5861
else NoDenotation
5962

compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,10 @@ trait TypeAssigner {
156156
val pre = maybeSkolemizePrefix(qualType, name)
157157
val mbr =
158158
if ctx.isJava then
159-
ctx.javaFindMember(name, pre)
159+
// don't look in the companion class here if qual is a module,
160+
// we use backtracking to instead change the qual to the companion class
161+
// if this fails.
162+
ctx.javaFindMember(name, pre, lookInCompanion = false)
160163
else
161164
qualType.findMember(name, pre)
162165

0 commit comments

Comments
 (0)