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