Skip to content

Commit

Permalink
Alternative fix based on tpd.desugarIdent
Browse files Browse the repository at this point in the history
  • Loading branch information
odersky committed Feb 12, 2022
1 parent b0556ee commit 64c04d5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
def genLoadQualUnlessElidable(): Unit = { if (!qualSafeToElide) { genLoadQualifier(tree) } }

// receiverClass is used in the bytecode to access the field. using sym.owner may lead to IllegalAccessError
def receiverClass = qualifier.tpe.widenTermRefExpr.finalResultType.typeSymbol
def receiverClass = qualifier.tpe.typeSymbol
if (sym.is(Module)) {
genLoadQualUnlessElidable()
genLoadModule(tree)
Expand Down
6 changes: 5 additions & 1 deletion compiler/src/dotty/tools/dotc/ast/tpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1383,7 +1383,11 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
/** Recover identifier prefix (e.g. this) if it exists */
def desugarIdentPrefix(tree: Ident)(using Context): Tree = tree.tpe match {
case TermRef(prefix: TermRef, _) =>
ref(prefix)
prefix.info match
case mt: MethodType if mt.paramInfos.isEmpty && mt.resultType.typeSymbol.is(Module) =>
ref(mt.resultType.typeSymbol.sourceModule)
case _ =>
ref(prefix)
case TermRef(prefix: ThisType, _) =>
This(prefix.cls)
case _ =>
Expand Down

0 comments on commit 64c04d5

Please sign in to comment.