@@ -683,18 +683,37 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
683
683
assignType(cpy.If (tree)(cond1, thenp2, elsep2), thenp2, elsep2)
684
684
}
685
685
686
- private def decomposeProtoFunction (pt : Type , defaultArity : Int )(implicit ctx : Context ): (List [Type ], Type ) = pt match {
687
- case _ if defn.isNonDepFunctionType(pt) =>
688
- // if expected parameter type(s) are wildcards, approximate from below.
689
- // if expected result type is a wildcard, approximate from above.
690
- // this can type the greatest set of admissible closures.
691
- val funType = pt.dealias
692
- (funType.argTypesLo.init, funType.argTypesHi.last)
693
- case SAMType (meth) =>
694
- val mt @ MethodTpe (_, formals, restpe) = meth.info
695
- (formals, if (mt.isDependent) WildcardType else restpe)
696
- case _ =>
697
- (List .tabulate(defaultArity)(alwaysWildcardType), WildcardType )
686
+ /** Decompose function prototype into a list of parameter prototypes and a result prototype
687
+ * tree, using WildcardTypes where a type is not known.
688
+ * For the result type we do this even if the expected type is not fully
689
+ * defined, which is a bit of a hack. But it's needed to make the following work
690
+ * (see typers.scala and printers/PlainPrinter.scala for examples).
691
+ *
692
+ * def double(x: Char): String = s"$x$x"
693
+ * "abc" flatMap double
694
+ */
695
+ private def decomposeProtoFunction (pt : Type , defaultArity : Int )(implicit ctx : Context ): (List [Type ], untpd.Tree ) = {
696
+ def typeTree (tp : Type ) = tp match {
697
+ case _ : WildcardType => untpd.TypeTree ()
698
+ case _ => untpd.TypeTree (tp)
699
+ }
700
+ pt match {
701
+ case _ if defn.isNonDepFunctionType(pt) =>
702
+ // if expected parameter type(s) are wildcards, approximate from below.
703
+ // if expected result type is a wildcard, approximate from above.
704
+ // this can type the greatest set of admissible closures.
705
+ val funType = pt.dealias
706
+ (funType.argTypesLo.init, typeTree(funType.argTypesHi.last))
707
+ case SAMType (meth) =>
708
+ val mt @ MethodTpe (_, formals, restpe) = meth.info
709
+ (formals,
710
+ if (mt.isDependent)
711
+ untpd.DependentTypeTree (syms => restpe.substParams(mt, syms.map(_.termRef)))
712
+ else
713
+ typeTree(restpe))
714
+ case _ =>
715
+ (List .tabulate(defaultArity)(alwaysWildcardType), untpd.TypeTree ())
716
+ }
698
717
}
699
718
700
719
def typedFunction (tree : untpd.Function , pt : Type )(implicit ctx : Context ) = track(" typedFunction" ) {
@@ -756,7 +775,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
756
775
case _ =>
757
776
}
758
777
759
- val (protoFormals, protoResult ) = decomposeProtoFunction(pt, params.length)
778
+ val (protoFormals, resultTpt ) = decomposeProtoFunction(pt, params.length)
760
779
761
780
def refersTo (arg : untpd.Tree , param : untpd.ValDef ): Boolean = arg match {
762
781
case Ident (name) => name == param.name
@@ -865,19 +884,6 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
865
884
else cpy.ValDef (param)(
866
885
tpt = untpd.TypeTree (
867
886
inferredParamType(param, protoFormal(i)).underlyingIfRepeated(isJava = false )))
868
-
869
- // Define result type of closure as the expected type, thereby pushing
870
- // down any implicit searches. We do this even if the expected type is not fully
871
- // defined, which is a bit of a hack. But it's needed to make the following work
872
- // (see typers.scala and printers/PlainPrinter.scala for examples).
873
- //
874
- // def double(x: Char): String = s"$x$x"
875
- // "abc" flatMap double
876
- //
877
- val resultTpt = protoResult match {
878
- case WildcardType (_) => untpd.TypeTree ()
879
- case _ => untpd.TypeTree (protoResult)
880
- }
881
887
val inlineable = pt.hasAnnotation(defn.InlineParamAnnot )
882
888
desugar.makeClosure(inferredParams, fnBody, resultTpt, inlineable)
883
889
}
@@ -1700,7 +1706,8 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
1700
1706
case tree : untpd.PackageDef => typedPackageDef(tree)
1701
1707
case tree : untpd.Annotated => typedAnnotated(tree, pt)
1702
1708
case tree : untpd.TypedSplice => typedTypedSplice(tree)
1703
- case tree : untpd.UnApply => typedUnApply(tree, pt)
1709
+ case tree : untpd.UnApply => typedUnApply(tree, pt)
1710
+ case tree : untpd.DependentTypeTree => typed(untpd.TypeTree ().withPos(tree.pos), pt)
1704
1711
case tree @ untpd.PostfixOp (qual, Ident (nme.WILDCARD )) => typedAsFunction(tree, pt)
1705
1712
case untpd.EmptyTree => tpd.EmptyTree
1706
1713
case _ => typedUnadapted(desugar(tree), pt)
0 commit comments