Skip to content

Commit e886676

Browse files
authored
Merge pull request #11472 from dotty-staging/fix-10868
Fix #10868: Handle semantic name in Java source code
2 parents 9532e41 + 37ab3b3 commit e886676

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import dotty.tools.dotc.core.Constants.Constant
66
import dotty.tools.dotc.core.Flags
77
import dotty.tools.dotc.core.Flags.FlagSet
88

9-
109
import JavaTokens._
1110
import JavaScanners._
1211
import Scanners.Offset

compiler/src/dotty/tools/dotc/typer/Typer.scala

+19-5
Original file line numberDiff line numberDiff line change
@@ -596,13 +596,27 @@ class Typer extends Namer
596596
.withSpan(tree.span)
597597
.computeNullable()
598598

599-
def typeSelectOnType(qual: untpd.Tree)(using Context) =
600-
typedSelect(untpd.cpy.Select(tree)(qual, tree.name.toTypeName), pt)
599+
def javaSelectOnType(qual: Tree)(using Context) =
600+
// semantic name conversion for `O$` in java code
601+
if !qual.symbol.is(JavaDefined) then
602+
val tree2 = untpd.cpy.Select(tree)(qual, tree.name.unmangleClassName)
603+
assignType(tree2, qual)
604+
else
605+
assignType(cpy.Select(tree)(qual, tree.name), qual)
601606

602607
def tryJavaSelectOnType(using Context): Tree = tree.qualifier match {
603-
case Select(qual, name) => typeSelectOnType(untpd.Select(qual, name.toTypeName))
604-
case Ident(name) => typeSelectOnType(untpd.Ident(name.toTypeName))
605-
case _ => errorTree(tree, "cannot convert to type selection") // will never be printed due to fallback
608+
case sel @ Select(qual, name) =>
609+
val qual1 = untpd.cpy.Select(sel)(qual, name.toTypeName)
610+
val qual2 = typedType(qual1, WildcardType)
611+
javaSelectOnType(qual2)
612+
613+
case id @ Ident(name) =>
614+
val qual1 = untpd.cpy.Ident(id)(name.toTypeName)
615+
val qual2 = typedType(qual1, WildcardType)
616+
javaSelectOnType(qual2)
617+
618+
case _ =>
619+
errorTree(tree, "cannot convert to type selection") // will never be printed due to fallback
606620
}
607621

608622
def selectWithFallback(fallBack: Context ?=> Tree) =

tests/pos-java-interop/i10868/J.java

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
class J { T.O$ o; }

tests/pos-java-interop/i10868/T.scala

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
trait T { object O }

0 commit comments

Comments
 (0)