diff --git a/compiler/src/dotty/tools/dotc/ast/Desugar.scala b/compiler/src/dotty/tools/dotc/ast/Desugar.scala index 30dad2f44847..a4ddf4348b87 100644 --- a/compiler/src/dotty/tools/dotc/ast/Desugar.scala +++ b/compiler/src/dotty/tools/dotc/ast/Desugar.scala @@ -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), diff --git a/compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala b/compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala index de558d2494b3..388656677a28 100644 --- a/compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala +++ b/compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala @@ -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 @@ -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] = { diff --git a/compiler/src/dotty/tools/dotc/transform/LambdaLift.scala b/compiler/src/dotty/tools/dotc/transform/LambdaLift.scala index fcae7ddbd0ee..6cd1ad06156a 100644 --- a/compiler/src/dotty/tools/dotc/transform/LambdaLift.scala +++ b/compiler/src/dotty/tools/dotc/transform/LambdaLift.scala @@ -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) } diff --git a/tests/generic-java-signatures/i3476.check b/tests/generic-java-signatures/i3476.check new file mode 100644 index 000000000000..d86bac9de59a --- /dev/null +++ b/tests/generic-java-signatures/i3476.check @@ -0,0 +1 @@ +OK diff --git a/tests/generic-java-signatures/i3476.scala b/tests/generic-java-signatures/i3476.scala new file mode 100644 index 000000000000..4af0b77b98a5 --- /dev/null +++ b/tests/generic-java-signatures/i3476.scala @@ -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 +} +