Skip to content

Fix #10868: Handle semantic name in Java source code #11472

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import dotty.tools.dotc.core.Constants.Constant
import dotty.tools.dotc.core.Flags
import dotty.tools.dotc.core.Flags.FlagSet


import JavaTokens._
import JavaScanners._
import Scanners.Offset
Expand Down
24 changes: 19 additions & 5 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -596,13 +596,27 @@ class Typer extends Namer
.withSpan(tree.span)
.computeNullable()

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

def tryJavaSelectOnType(using Context): Tree = tree.qualifier match {
case Select(qual, name) => typeSelectOnType(untpd.Select(qual, name.toTypeName))
case Ident(name) => typeSelectOnType(untpd.Ident(name.toTypeName))
case _ => errorTree(tree, "cannot convert to type selection") // will never be printed due to fallback
case sel @ Select(qual, name) =>
val qual1 = untpd.cpy.Select(sel)(qual, name.toTypeName)
val qual2 = typedType(qual1, WildcardType)
javaSelectOnType(qual2)

case id @ Ident(name) =>
val qual1 = untpd.cpy.Ident(id)(name.toTypeName)
val qual2 = typedType(qual1, WildcardType)
javaSelectOnType(qual2)

case _ =>
errorTree(tree, "cannot convert to type selection") // will never be printed due to fallback
}

def selectWithFallback(fallBack: Context ?=> Tree) =
Expand Down
1 change: 1 addition & 0 deletions tests/pos-java-interop/i10868/J.java
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class J { T.O$ o; }
1 change: 1 addition & 0 deletions tests/pos-java-interop/i10868/T.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
trait T { object O }