Skip to content

Commit

Permalink
tweak: try the original name first and then fallback to module
Browse files Browse the repository at this point in the history
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
1 parent 22d98d6 commit 4cb34e5
Showing 1 changed file with 10 additions and 7 deletions.
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

0 comments on commit 4cb34e5

Please sign in to comment.