Skip to content
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
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