Skip to content

Commit 27d632e

Browse files
liufengyunsmarter
andcommitted
Fix #10888: Avoid A.this.B for Java inner classes
For Java inner classes, we should use `A#B` instead of `A.this.B`. Co-authored-by: Guillaume Martres <[email protected]>
1 parent c9bf740 commit 27d632e

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -349,12 +349,18 @@ class ClassfileParser(
349349
val tag = sig(index); index += 1
350350
(tag: @switch) match {
351351
case 'L' =>
352-
def processInner(tp: Type): Type = tp match {
353-
case tp: TypeRef if !tp.symbol.owner.is(Flags.ModuleClass) =>
354-
TypeRef(processInner(tp.prefix.widen), tp.symbol.asType)
355-
case _ =>
356-
tp
357-
}
352+
/** Inner class references of A.this.B into A#B, do the same transformation recursively on `A` */
353+
def reachableType(symbol: Symbol): Type =
354+
if symbol.is(Flags.Package) then
355+
ThisType.raw(TypeRef(NoPrefix, symbol.asType))
356+
else if symbol.isType then
357+
ThisType.raw(TypeRef(reachableType(symbol.owner), symbol.asType))
358+
else
359+
throw new RuntimeException("unexpected term symbol " + symbol)
360+
361+
def innerType(symbol: Symbol): Type =
362+
TypeRef(reachableType(symbol.owner), symbol)
363+
358364
def processClassType(tp: Type): Type = tp match {
359365
case tp: TypeRef =>
360366
if (sig(index) == '<') {
@@ -388,13 +394,13 @@ class ClassfileParser(
388394
}
389395

390396
val classSym = classNameToSymbol(subName(c => c == ';' || c == '<'))
391-
val classTpe = if (classSym eq defn.ObjectClass) defn.FromJavaObjectType else classSym.typeRef
392-
var tpe = processClassType(processInner(classTpe))
397+
val classTpe = if (classSym eq defn.ObjectClass) defn.FromJavaObjectType else innerType(classSym)
398+
var tpe = processClassType(classTpe)
393399
while (sig(index) == '.') {
394400
accept('.')
395401
val name = subName(c => c == ';' || c == '<' || c == '.').toTypeName
396402
val clazz = tpe.member(name).symbol
397-
tpe = processClassType(processInner(TypeRef(tpe, clazz)))
403+
tpe = processClassType(innerType(clazz))
398404
}
399405
accept(';')
400406
tpe

0 commit comments

Comments
 (0)