Skip to content

Commit

Permalink
Merge pull request #12710 from lrytz/i10347
Browse files Browse the repository at this point in the history
Emit generic signature for static forwarders to nullary methods
  • Loading branch information
smarter authored Jun 15, 2021
2 parents 16e07f4 + 5c8188a commit e7f6a81
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 13 deletions.
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/backend/jvm/BCodeHelpers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import dotty.tools.dotc.core.Types
import dotty.tools.dotc.core.Types._
import dotty.tools.dotc.core.TypeErasure
import dotty.tools.dotc.transform.GenericSignatures
import dotty.tools.dotc.transform.ElimErasedValueType
import dotty.tools.io.AbstractFile
import dotty.tools.dotc.report

Expand Down Expand Up @@ -926,7 +927,7 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
// (one that doesn't erase to the actual signature). See run/t3452b for a test case.

val memberTpe = atPhase(erasurePhase) { moduleClass.denot.thisType.memberInfo(sym) }
val erasedMemberType = TypeErasure.fullErasure(memberTpe)
val erasedMemberType = ElimErasedValueType.elimEVT(TypeErasure.transformInfo(sym, memberTpe))
if (erasedMemberType =:= sym.denot.info)
getGenericSignatureHelper(sym, moduleClass, memberTpe).orNull
else null
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/TypeErasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
// See doc comment for ElimByName for speculation how we could improve this.
else
MethodType(Nil, Nil,
eraseResult(sym.info.finalResultType.translateFromRepeated(toArray = sourceLanguage.isJava)))
eraseResult(rt.translateFromRepeated(toArray = sourceLanguage.isJava)))
case tp1: PolyType =>
eraseResult(tp1.resultType) match
case rt: MethodType => rt
Expand Down
23 changes: 12 additions & 11 deletions compiler/src/dotty/tools/dotc/transform/ElimErasedValueType.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ import NameKinds.SuperAccessorName

object ElimErasedValueType {
val name: String = "elimErasedValueType"

def elimEVT(tp: Type)(using Context): Type = tp match {
case ErasedValueType(_, underlying) =>
elimEVT(underlying)
case tp: MethodType =>
val paramTypes = tp.paramInfos.mapConserve(elimEVT)
val retType = elimEVT(tp.resultType)
tp.derivedLambdaType(tp.paramNames, paramTypes, retType)
case _ =>
tp
}
}

/** This phase erases ErasedValueType to their underlying type.
Expand All @@ -25,6 +36,7 @@ object ElimErasedValueType {
class ElimErasedValueType extends MiniPhase with InfoTransformer { thisPhase =>

import tpd._
import ElimErasedValueType.elimEVT

override def phaseName: String = ElimErasedValueType.name

Expand All @@ -48,17 +60,6 @@ class ElimErasedValueType extends MiniPhase with InfoTransformer { thisPhase =>
elimEVT(tp)
}

def elimEVT(tp: Type)(using Context): Type = tp match {
case ErasedValueType(_, underlying) =>
elimEVT(underlying)
case tp: MethodType =>
val paramTypes = tp.paramInfos.mapConserve(elimEVT)
val retType = elimEVT(tp.resultType)
tp.derivedLambdaType(tp.paramNames, paramTypes, retType)
case _ =>
tp
}

def transformTypeOfTree(tree: Tree)(using Context): Tree =
tree.withType(elimEVT(tree.tpe))

Expand Down
7 changes: 7 additions & 0 deletions tests/pos/i10347/A_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
trait L[+T] { def head: T }
class K(val s: String) extends AnyVal
object A {
def foo: L[String] = ???
def bar: L[K] = ???
def baz(k: K): L[String] = ???
}
5 changes: 5 additions & 0 deletions tests/pos/i10347/C_2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class C_2 {
String hi = A.foo().head();
String hy = A.bar().head();
String hj = A.baz("").head();
}

0 comments on commit e7f6a81

Please sign in to comment.