Skip to content

Commit

Permalink
Fix #18769: Allow HK type args in Java signatures. (#18883)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sjrd authored Nov 9, 2023
2 parents a90db4f + f29b3d6 commit 4eae174
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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) =
Expand Down
9 changes: 9 additions & 0 deletions tests/pos/i18769.scala
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit 4eae174

Please sign in to comment.