Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(#17255): cannot find Scala companion module from Java #19773

Merged
Prev Previous commit
Next Next commit
tweak: try the original name first and then fallback to module
Avoid skipping searchin a member by the original name even when name is likely
companion module name.
  • Loading branch information
i10416 committed Feb 24, 2024
commit 4cb34e5b6134c3bccc25dc61ff53da80f992aaa3
17 changes: 10 additions & 7 deletions compiler/src/dotty/tools/dotc/core/ContextOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,16 @@ object ContextOps:
val preSym = pre.typeSymbol
// 1. Try to search in current type and parents.
val directSearch =
if name.isTypeName && name.endsWith(StdNames.str.MODULE_SUFFIX) then
pre.findMember(name.stripModuleClassSuffix, pre, required, excluded) match
case NoDenotation => NoDenotation
case symDenot: SymDenotation =>
symDenot.companionModule.denot
else
pre.findMember(name, pre, required, excluded)
def asModule =
if name.isTypeName && name.endsWith(StdNames.str.MODULE_SUFFIX) then
pre.findMember(name.stripModuleClassSuffix, pre, required, excluded) match
i10416 marked this conversation as resolved.
Show resolved Hide resolved
case NoDenotation => NoDenotation
case symDenot: SymDenotation =>
symDenot.companionModule.denot
else NoDenotation
pre.findMember(name, pre, required, excluded) match
case NoDenotation => asModule
case denot => denot

// 2. Try to search in companion class if current is an object.
def searchCompanionClass = if lookInCompanion && preSym.is(Flags.Module) then
Expand Down
Loading