Skip to content

Fix #3476: Add Artifact flag to closures #3503

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 6 commits into from
Apr 10, 2018
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
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ object desugar {
* If `inlineable` is true, tag $anonfun with an @inline annotation.
*/
def makeClosure(params: List[ValDef], body: Tree, tpt: Tree = TypeTree(), inlineable: Boolean)(implicit ctx: Context) = {
var mods = synthetic
var mods = synthetic | Artifact
if (inlineable) mods |= Inline
Block(
DefDef(nme.ANON_FUN, Nil, params :: Nil, tpt, body).withMods(mods),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import core.TypeErasure.erasure
import core.Types._
import core.classfile.ClassfileConstants
import ast.Trees._
import SymUtils._
import TypeUtils._
import java.lang.StringBuilder

Expand All @@ -27,8 +28,11 @@ object GenericSignatures {
* @param info The type of the symbol
* @return The signature if it could be generated, `None` otherwise.
*/
def javaSig(sym0: Symbol, info: Type)(implicit ctx: Context): Option[String] =
javaSig0(sym0, info)(ctx.withPhase(ctx.erasurePhase))
def javaSig(sym0: Symbol, info: Type)(implicit ctx: Context): Option[String] = {
// Avoid generating a signature for local symbols.
if (sym0.isLocal) None
else javaSig0(sym0, info)(ctx.withPhase(ctx.erasurePhase))
}

@noinline
private final def javaSig0(sym0: Symbol, info: Type)(implicit ctx: Context): Option[String] = {
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/LambdaLift.scala
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ object LambdaLift {
local.copySymDenotation(
owner = newOwner,
name = newName(local),
initFlags = local.flags &~ Module &~ Final | Private | maybeStatic,
initFlags = local.flags &~ Module &~ Final | Private | Lifted | maybeStatic,
// drop Module because class is no longer a singleton in the lifted context.
info = liftedInfo(local)).installAfter(thisPhase)
}
Expand Down
1 change: 1 addition & 0 deletions tests/generic-java-signatures/i3476.check
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
OK
98 changes: 98 additions & 0 deletions tests/generic-java-signatures/i3476.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
object Test {

def hasGenericSignature(cls: Class[_], methName: String): Boolean = {
cls.getDeclaredMethods().find(_.getName.contains(methName)) match {
case None => throw new NoSuchMethodError(s"No $methName in ${cls.getName}")
case Some(meth) => meth.getTypeParameters.nonEmpty
}
}

def checkHasGenericSignature(cls: Class[_], methName: String): Unit =
assert(hasGenericSignature(cls, methName))

def checkDoesntHaveGenericSignature(cls: Class[_], methName: String): Unit =
assert(!hasGenericSignature(cls, methName))

def main(args: Array[String]): Unit = {

checkHasGenericSignature(classOf[TopLevelClass], "meth")
checkHasGenericSignature(classOf[AbstractTopLevelClass], "meth")
checkHasGenericSignature(classOf[TopLevelClass#InsideClass], "meth")
checkHasGenericSignature(classOf[TopLevelClass#AbstractInsideClass], "meth")
checkDoesntHaveGenericSignature(new TopLevelClass().localClass, "meth")
checkDoesntHaveGenericSignature(new TopLevelClass().otherLocalClass, "meth")

checkHasGenericSignature(TopLevelObject.getClass, "meth")
checkHasGenericSignature(classOf[TopLevelObject.InsideObject], "meth")
checkHasGenericSignature(classOf[TopLevelObject.AbstractInsideObject], "meth")
checkDoesntHaveGenericSignature(TopLevelObject.localClass, "meth")
checkDoesntHaveGenericSignature(TopLevelObject.otherLocalClass, "meth")

println("OK")
}
}

object TopLevelObject {
def meth[T](x: T): T = x

def localObject: Class[_] = {
object LocalObject {
def meth[T](x: T): T = x
}
LocalObject.getClass
}

def localClass: Class[_] = {
class LocalClass {
def meth[T](x: T): T = x
}
classOf[LocalClass]
}

val otherLocalClass: Class[_] = {
class LocalClass {
def meth[T](x: T): T = x
}
classOf[LocalClass]
}

class InsideObject {
def meth[T](x: T): T = x
}

abstract class AbstractInsideObject {
def meth[T](x: T): T = x
}
}

class TopLevelClass {

def meth[T](x: T): T = x

def localClass: Class[_] = {
class LocalClass {
def meth[T](x: T): T = x
}
classOf[LocalClass]
}

val otherLocalClass: Class[_] = {
class LocalClass {
def meth[T](x: T): T = x
}
classOf[LocalClass]
}

class InsideClass {
def meth[T](x: T): T = x
}

abstract class AbstractInsideClass {
def meth[T](x: T): T = x
}
}

abstract class AbstractTopLevelClass {
def meth[T](x: T): T = x
}