@@ -400,30 +400,38 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
400
400
}
401
401
402
402
def typedTyped (tree : untpd.Typed , pt : Type )(implicit ctx : Context ): Tree = track(" typedTyped" ) {
403
- def regularTyped (isWildcard : Boolean ) = {
404
- val tpt1 =
405
- if (untpd.isWildcardStarArg(tree))
406
- TypeTree (defn.SeqType .appliedTo(pt :: Nil ))
407
- else
408
- checkSimpleKinded(typedType(tree.tpt))
409
- val expr1 =
410
- if (isWildcard) tree.expr withType tpt1.tpe
411
- else typed(tree.expr, tpt1.tpe.widenSkolem)
412
- assignType(cpy.Typed (tree)(expr1, tpt1), tpt1)
413
- }
414
- tree.expr match {
403
+ /* Handles three cases:
404
+ * @param ifPat how to handle a pattern (_: T)
405
+ * @param ifExpr how to handle an expression (e: T)
406
+ * @param wildName what name `w` to use in the rewriting of
407
+ * (x: T) to (x @ (w: T)). This is either `_` or `_*`.
408
+ */
409
+ def cases (ifPat : => Tree , ifExpr : => Tree , wildName : TermName ) = tree.expr match {
415
410
case id : untpd.Ident if (ctx.mode is Mode .Pattern ) && isVarPattern(id) =>
416
- if (id.name == nme.WILDCARD || id.name == nme.WILDCARD_STAR ) regularTyped(isWildcard = true )
411
+ if (id.name == nme.WILDCARD || id.name == nme.WILDCARD_STAR ) ifPat
417
412
else {
418
413
import untpd ._
419
- val name = if (untpd.isWildcardStarArg(tree)) nme.WILDCARD_STAR else nme.WILDCARD
420
- typed(Bind (id.name, Typed (Ident (name), tree.tpt)).withPos(id.pos), pt)
414
+ typed(Bind (id.name, Typed (Ident (wildName), tree.tpt)).withPos(id.pos), pt)
421
415
}
422
- case _ =>
423
- if (untpd.isWildcardStarArg(tree))
424
- seqToRepeated(typedExpr(tree.expr, defn.SeqType ))
425
- else
426
- regularTyped(isWildcard = false )
416
+ case _ => ifExpr
417
+ }
418
+ def ascription (tpt : Tree , isWildcard : Boolean ) = {
419
+ val expr1 =
420
+ if (isWildcard) tree.expr.withType(tpt.tpe)
421
+ else typed(tree.expr, tpt.tpe.widenSkolem)
422
+ assignType(cpy.Typed (tree)(expr1, tpt), tpt)
423
+ }
424
+ if (untpd.isWildcardStarArg(tree))
425
+ cases(
426
+ ifPat = ascription(TypeTree (defn.SeqType .appliedTo(pt :: Nil )), isWildcard = true ),
427
+ ifExpr = seqToRepeated(typedExpr(tree.expr, defn.SeqType )),
428
+ wildName = nme.WILDCARD_STAR )
429
+ else {
430
+ def tpt1 = checkSimpleKinded(typedType(tree.tpt))
431
+ cases(
432
+ ifPat = ascription(tpt1, isWildcard = true ),
433
+ ifExpr = ascription(tpt1, isWildcard = false ),
434
+ wildName = nme.WILDCARD )
427
435
}
428
436
}
429
437
0 commit comments