@@ -4754,7 +4754,29 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
4754
4754
var typeArgs = tree match
4755
4755
case Select (qual, nme.CONSTRUCTOR ) => qual.tpe.widenDealias.argTypesLo.map(TypeTree (_))
4756
4756
case _ => Nil
4757
- if typeArgs.isEmpty then typeArgs = constrained(poly, tree)._2.map(_.wrapInTypeTree(tree))
4757
+ if typeArgs.isEmpty then
4758
+ val poly1 = tree match
4759
+ case Select (qual, nme.apply) => qual.tpe.widen match
4760
+ case defn.PolyFunctionOf (_) =>
4761
+ // Given a poly function, like the one in i6682a:
4762
+ // val v = [T] => (y:T) => (x:y.type) => 3
4763
+ // It's possible to apply `v(v)` which extends to:
4764
+ // v.apply[?T](v)
4765
+ // Requiring the circular constraint `v <: ?T`,
4766
+ // (because type parameter T occurs in v's type).
4767
+ // So we create a fresh copy of the outer
4768
+ // poly method type, so we now extend to:
4769
+ // v.apply[?T'](v)
4770
+ // Where `?T'` is a type var for a T' type parameter,
4771
+ // leading to the non-circular `v <: ?T'` constraint.
4772
+ //
4773
+ // This also happens in `assignType(tree: untpd.TypeApply, ..)`
4774
+ // to avoid any type arguments, containing the type lambda,
4775
+ // being applied to the very same type lambda.
4776
+ poly.newLikeThis(poly.paramNames, poly.paramInfos, poly.resType)
4777
+ case _ => poly
4778
+ case _ => poly
4779
+ typeArgs = constrained(poly1, tree)._2.map(_.wrapInTypeTree(tree))
4758
4780
convertNewGenericArray(readapt(tree.appliedToTypeTrees(typeArgs)))
4759
4781
case wtp =>
4760
4782
val isStructuralCall = wtp.isValueType && isStructuralTermSelectOrApply(tree)
0 commit comments