Skip to content

Commit 4eae174

Browse files
authored
Fix #18769: Allow HK type args in Java signatures. (#18883)
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.
2 parents a90db4f + f29b3d6 commit 4eae174

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala

+1-2
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ object GenericSignatures {
258258
if (sym == defn.PairClass && tupleArity(tp) > Definitions.MaxTupleArity)
259259
jsig(defn.TupleXXLClass.typeRef)
260260
else if (isTypeParameterInSig(sym, sym0)) {
261-
assert(!sym.isAliasType, "Unexpected alias type: " + sym)
261+
assert(!sym.isAliasType || sym.info.isLambdaSub, "Unexpected alias type: " + sym)
262262
typeParamSig(sym.name.lastPart)
263263
}
264264
else if (defn.specialErasure.contains(sym))
@@ -407,7 +407,6 @@ object GenericSignatures {
407407

408408

409409
// only refer to type params that will actually make it into the sig, this excludes:
410-
// * higher-order type parameters
411410
// * type parameters appearing in method parameters
412411
// * type members not visible in an enclosing template
413412
private def isTypeParameterInSig(sym: Symbol, initialSymbol: Symbol)(using Context) =

tests/pos/i18769.scala

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
trait Arb[Fx[_]] {
2+
def pure[A](x: A): Fx[A]
3+
}
4+
5+
class PfOps(private val self: Int) extends AnyVal {
6+
def pf[Fy[_]](m: Arb[Fy]): PartialFunction[Int, Fy[Int]] = {
7+
case x => m.pure(x)
8+
}
9+
}

0 commit comments

Comments
 (0)