From f29b3d6d41d60893e2cde283e2831263a17e6981 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Doeraene?= Date: Mon, 6 Nov 2023 18:08:57 +0100 Subject: [PATCH] Fix #18769: Allow HK type args in Java signatures. Contrary to what an earlier comment said, we do emit HK type parameters in Java signatures. They are always unbounded and never the type of values. However, they can appear as type arguments to other higher-kinded types. Previously, an assertion error would trigger in that situation. We relax the assertion to allow this situation and emit a correct Java signature. I manually verified that the generated Java signatures are consistent with what Scala 2 emits for the same code snippet. --- .../dotty/tools/dotc/transform/GenericSignatures.scala | 3 +-- tests/pos/i18769.scala | 9 +++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 tests/pos/i18769.scala diff --git a/compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala b/compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala index 77f4f76c33ba..88297e88ce7d 100644 --- a/compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala +++ b/compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala @@ -258,7 +258,7 @@ object GenericSignatures { if (sym == defn.PairClass && tupleArity(tp) > Definitions.MaxTupleArity) jsig(defn.TupleXXLClass.typeRef) else if (isTypeParameterInSig(sym, sym0)) { - assert(!sym.isAliasType, "Unexpected alias type: " + sym) + assert(!sym.isAliasType || sym.info.isLambdaSub, "Unexpected alias type: " + sym) typeParamSig(sym.name.lastPart) } else if (defn.specialErasure.contains(sym)) @@ -407,7 +407,6 @@ object GenericSignatures { // only refer to type params that will actually make it into the sig, this excludes: - // * higher-order type parameters // * type parameters appearing in method parameters // * type members not visible in an enclosing template private def isTypeParameterInSig(sym: Symbol, initialSymbol: Symbol)(using Context) = diff --git a/tests/pos/i18769.scala b/tests/pos/i18769.scala new file mode 100644 index 000000000000..be5db80b7727 --- /dev/null +++ b/tests/pos/i18769.scala @@ -0,0 +1,9 @@ +trait Arb[Fx[_]] { + def pure[A](x: A): Fx[A] +} + +class PfOps(private val self: Int) extends AnyVal { + def pf[Fy[_]](m: Arb[Fy]): PartialFunction[Int, Fy[Int]] = { + case x => m.pure(x) + } +}