@@ -4736,7 +4736,29 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
4736
4736
var typeArgs = tree match
4737
4737
case Select (qual, nme.CONSTRUCTOR ) => qual.tpe.widenDealias.argTypesLo.map(TypeTree (_))
4738
4738
case _ => Nil
4739
- if typeArgs.isEmpty then typeArgs = constrained(poly, tree)._2.map(_.wrapInTypeTree(tree))
4739
+ if typeArgs.isEmpty then
4740
+ val poly1 = tree match
4741
+ case Select (qual, nme.apply) => qual.tpe.widen match
4742
+ case defn.PolyFunctionOf (_) =>
4743
+ // Given a poly function, like the one in i6682a:
4744
+ // val v = [T] => (y:T) => (x:y.type) => 3
4745
+ // It's possible to apply `v(v)` which extends to:
4746
+ // v.apply[?T](v)
4747
+ // Requiring the circular constraint `v <: ?T`,
4748
+ // (because type parameter T occurs in v's type).
4749
+ // So we create a fresh copy of the outer
4750
+ // poly method type, so we now extend to:
4751
+ // v.apply[?T'](v)
4752
+ // Where `?T'` is a type var for a T' type parameter,
4753
+ // leading to the non-circular `v <: ?T'` constraint.
4754
+ //
4755
+ // This also happens in `assignType(tree: untpd.TypeApply, ..)`
4756
+ // to avoid any type arguments, containing the type lambda,
4757
+ // being applied to the very same type lambda.
4758
+ poly.newLikeThis(poly.paramNames, poly.paramInfos, poly.resType)
4759
+ case _ => poly
4760
+ case _ => poly
4761
+ typeArgs = constrained(poly1, tree)._2.map(_.wrapInTypeTree(tree))
4740
4762
convertNewGenericArray(readapt(tree.appliedToTypeTrees(typeArgs)))
4741
4763
case wtp =>
4742
4764
val isStructuralCall = wtp.isValueType && isStructuralTermSelectOrApply(tree)
0 commit comments