@@ -936,7 +936,7 @@ class Typer extends Namer
936936 * def double(x: Char): String = s"$x$x"
937937 * "abc" flatMap double
938938 */
939- private def decomposeProtoFunction (pt : Type , defaultArity : Int )(using Context ): (List [Type ], untpd.Tree ) = {
939+ private def decomposeProtoFunction (pt : Type , defaultArity : Int , tree : untpd. Tree )(using Context ): (List [Type ], untpd.Tree ) = {
940940 def typeTree (tp : Type ) = tp match {
941941 case _ : WildcardType => untpd.TypeTree ()
942942 case _ => untpd.TypeTree (tp)
@@ -947,7 +947,15 @@ class Typer extends Namer
947947 newTypeVar(apply(bounds.orElse(TypeBounds .empty)).bounds)
948948 case _ => mapOver(t)
949949 }
950- pt.stripTypeVar.dealias match {
950+ val pt1 = pt.stripTypeVar.dealias
951+ if (pt1 ne pt1.dropDependentRefinement)
952+ && defn.isContextFunctionType(pt1.nonPrivateMember(nme.apply).info.finalResultType)
953+ then
954+ ctx.error(
955+ i """ Implementation restriction: Expected result type $pt1
956+ |is a curried dependent context function type. Such types are not yet supported. """ ,
957+ tree.sourcePos)
958+ pt1 match {
951959 case pt1 if defn.isNonRefinedFunction(pt1) =>
952960 // if expected parameter type(s) are wildcards, approximate from below.
953961 // if expected result type is a wildcard, approximate from above.
@@ -960,7 +968,7 @@ class Typer extends Namer
960968 else
961969 typeTree(restpe))
962970 case tp : TypeParamRef =>
963- decomposeProtoFunction(ctx.typerState.constraint.entry(tp).bounds.hi, defaultArity)
971+ decomposeProtoFunction(ctx.typerState.constraint.entry(tp).bounds.hi, defaultArity, tree )
964972 case _ =>
965973 (List .tabulate(defaultArity)(alwaysWildcardType), untpd.TypeTree ())
966974 }
@@ -1251,7 +1259,7 @@ class Typer extends Namer
12511259 typedMatchFinish(tree, tpd.EmptyTree , defn.ImplicitScrutineeTypeRef , cases1, pt)
12521260 }
12531261 else {
1254- val (protoFormals, _) = decomposeProtoFunction(pt, 1 )
1262+ val (protoFormals, _) = decomposeProtoFunction(pt, 1 , tree )
12551263 val checkMode =
12561264 if (pt.isRef(defn.PartialFunctionClass )) desugar.MatchCheck .None
12571265 else desugar.MatchCheck .Exhaustive
0 commit comments