@@ -2501,7 +2501,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
25012501 case rhs => typedExpr(rhs, tpt1.tpe.widenExpr)
25022502 }
25032503 val vdef1 = assignType(cpy.ValDef (vdef)(name, tpt1, rhs1), sym)
2504- postProcessInfo(sym)
2504+ postProcessInfo(vdef1, sym)
25052505 vdef1.setDefTree
25062506 }
25072507
@@ -4391,7 +4391,29 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
43914391 var typeArgs = tree match
43924392 case Select (qual, nme.CONSTRUCTOR ) => qual.tpe.widenDealias.argTypesLo.map(TypeTree (_))
43934393 case _ => Nil
4394- if typeArgs.isEmpty then typeArgs = constrained(poly, tree)._2.map(_.wrapInTypeTree(tree))
4394+ if typeArgs.isEmpty then
4395+ val poly1 = tree match
4396+ case Select (qual, nme.apply) => qual.tpe.widen match
4397+ case defn.PolyFunctionOf (_) =>
4398+ // Given a poly function, like the one in i6682a:
4399+ // val v = [T] => (y:T) => (x:y.type) => 3
4400+ // It's possible to apply `v(v)` which extends to:
4401+ // v.apply[?T](v)
4402+ // Requiring the circular constraint `v <: ?T`,
4403+ // (because type parameter T occurs in v's type).
4404+ // So we create a fresh copy of the outer
4405+ // poly method type, so we now extend to:
4406+ // v.apply[?T'](v)
4407+ // Where `?T'` is a type var for a T' type parameter,
4408+ // leading to the non-circular `v <: ?T'` constraint.
4409+ //
4410+ // This also happens in `assignType(tree: untpd.TypeApply, ..)`
4411+ // to avoid any type arguments, containing the type lambda,
4412+ // being applied to the very same type lambda.
4413+ poly.newLikeThis(poly.paramNames, poly.paramInfos, poly.resType)
4414+ case _ => poly
4415+ case _ => poly
4416+ typeArgs = constrained(poly1, tree)._2.map(_.wrapInTypeTree(tree))
43954417 convertNewGenericArray(readapt(tree.appliedToTypeTrees(typeArgs)))
43964418 case wtp =>
43974419 val isStructuralCall = wtp.isValueType && isStructuralTermSelectOrApply(tree)
0 commit comments