@@ -572,7 +572,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
572
572
def typedBlock (tree : untpd.Block , pt : Type )(implicit ctx : Context ) = track(" typedBlock" ) {
573
573
val exprCtx = index(tree.stats)
574
574
val stats1 = typedStats(tree.stats, ctx.owner)
575
- val expr1 = typedExpr(tree.expr, pt)(exprCtx)
575
+ val expr1 = typedExpr(tree.expr, pt.weakenProto )(exprCtx)
576
576
ensureNoLocalRefs(
577
577
assignType(cpy.Block (tree)(stats1, expr1), stats1, expr1), pt, localSyms(stats1))
578
578
}
@@ -619,8 +619,8 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
619
619
620
620
def typedIf (tree : untpd.If , pt : Type )(implicit ctx : Context ) = track(" typedIf" ) {
621
621
val cond1 = typed(tree.cond, defn.BooleanType )
622
- val thenp1 = typed(tree.thenp, pt)
623
- val elsep1 = typed(tree.elsep orElse (untpd.unitLiteral withPos tree.pos), pt)
622
+ val thenp1 = typed(tree.thenp, pt.weakenProto )
623
+ val elsep1 = typed(tree.elsep orElse (untpd.unitLiteral withPos tree.pos), pt.weakenProto )
624
624
val thenp2 :: elsep2 :: Nil = harmonize(thenp1 :: elsep1 :: Nil )
625
625
assignType(cpy.If (tree)(cond1, thenp2, elsep2), thenp2, elsep2)
626
626
}
@@ -793,7 +793,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
793
793
val selType = widenForMatchSelector(
794
794
fullyDefinedType(sel1.tpe, " pattern selector" , tree.pos))
795
795
796
- val cases1 = typedCases(tree.cases, selType, pt)
796
+ val cases1 = typedCases(tree.cases, selType, pt.weakenProto )
797
797
val cases2 = harmonize(cases1).asInstanceOf [List [CaseDef ]]
798
798
assignType(cpy.Match (tree)(sel1, cases2), cases2)
799
799
}
@@ -920,8 +920,8 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
920
920
}
921
921
922
922
def typedTry (tree : untpd.Try , pt : Type )(implicit ctx : Context ): Try = track(" typedTry" ) {
923
- val expr1 = typed(tree.expr, pt)
924
- val cases1 = typedCases(tree.cases, defn.ThrowableType , pt)
923
+ val expr1 = typed(tree.expr, pt.weakenProto )
924
+ val cases1 = typedCases(tree.cases, defn.ThrowableType , pt.weakenProto )
925
925
val finalizer1 = typed(tree.finalizer, defn.UnitType )
926
926
val expr2 :: cases2x = harmonize(expr1 :: cases1)
927
927
val cases2 = cases2x.asInstanceOf [List [CaseDef ]]
@@ -1525,18 +1525,24 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
1525
1525
* 2nd strategy: If tree is a select `qual.name`, try to insert an implicit conversion
1526
1526
* around the qualifier part `qual` so that the result conforms to the expected type
1527
1527
* with wildcard result type.
1528
+ *
1529
+ * If `pt` is a weak prototype, only try to insert the implicit on qualifier. If that
1530
+ * fails, succeed anyway with the idea that the `apply` can still be inserted further out.
1531
+ * where the actual application is.
1528
1532
*/
1529
1533
def tryInsertApplyOrImplicit (tree : Tree , pt : ProtoType )(fallBack : (Tree , TyperState ) => Tree )(implicit ctx : Context ): Tree =
1530
- tryEither { implicit ctx =>
1531
- val sel = typedSelect(untpd.Select (untpd.TypedSplice (tree), nme.apply), pt)
1532
- if (sel.tpe.isError) sel else adapt(sel, pt)
1533
- } { (failedTree, failedState) =>
1534
- tryInsertImplicitOnQualifier(tree, pt).getOrElse(fallBack(failedTree, failedState))
1535
- }
1534
+ if (pt.isWeakProto)
1535
+ tryInsertImplicitOnQualifier(tree, pt).getOrElse(tree)
1536
+ else
1537
+ tryEither { implicit ctx =>
1538
+ val sel = typedSelect(untpd.Select (untpd.TypedSplice (tree), nme.apply), pt)
1539
+ if (sel.tpe.isError) sel else adapt(sel, pt)
1540
+ } { (failedTree, failedState) =>
1541
+ tryInsertImplicitOnQualifier(tree, pt).getOrElse(fallBack(failedTree, failedState))
1542
+ }
1536
1543
1537
1544
/** If this tree is a select node `qual.name`, try to insert an implicit conversion
1538
- * `c` around `qual` so that `c(qual).name` conforms to `pt`. If that fails
1539
- * return `tree` itself.
1545
+ * `c` around `qual` so that `c(qual).name` conforms to `pt`.
1540
1546
*/
1541
1547
def tryInsertImplicitOnQualifier (tree : Tree , pt : Type )(implicit ctx : Context ): Option [Tree ] = ctx.traceIndented(i " try insert impl on qualifier $tree $pt" ) {
1542
1548
tree match {
0 commit comments