Skip to content

Commit 714fffc

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 c3e26df commit 714fffc

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -349,12 +349,15 @@ 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+
/** A type representation where inner classes become `A#B` instead of `A.this.B` (like with `typeRef`) */
353+
def innerType(symbol: Symbol): Type =
354+
if symbol.is(Flags.Package) then
355+
symbol.thisType
356+
else if symbol.isType then
357+
TypeRef(innerType(symbol.owner), symbol)
358+
else
359+
throw new RuntimeException("unexpected term symbol " + symbol)
360+
358361
def processClassType(tp: Type): Type = tp match {
359362
case tp: TypeRef =>
360363
if (sig(index) == '<') {
@@ -388,13 +391,13 @@ class ClassfileParser(
388391
}
389392

390393
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))
394+
val classTpe = if (classSym eq defn.ObjectClass) defn.FromJavaObjectType else innerType(classSym)
395+
var tpe = processClassType(classTpe)
393396
while (sig(index) == '.') {
394397
accept('.')
395398
val name = subName(c => c == ';' || c == '<' || c == '.').toTypeName
396-
val clazz = tpe.member(name).symbol
397-
tpe = processClassType(processInner(TypeRef(tpe, clazz)))
399+
val clsTpe = tpe.select(name)
400+
tpe = processClassType(clsTpe)
398401
}
399402
accept(';')
400403
tpe

0 commit comments

Comments
 (0)