@@ -398,8 +398,9 @@ trait Applications extends Compatibility { self: Typer =>
398
398
399
399
val result = {
400
400
var typedArgs = typedArgBuf.toList
401
- val ownType =
402
- if (! success) ErrorType
401
+ val app0 = cpy.Apply (app, normalizedFun, typedArgs)
402
+ val app1 =
403
+ if (! success) app0.withType(ErrorType )
403
404
else {
404
405
if (! sameSeq(args, orderedArgs)) {
405
406
// need to lift arguments to maintain evaluation order in the
@@ -411,9 +412,9 @@ trait Applications extends Compatibility { self: Typer =>
411
412
}
412
413
if (sameSeq(typedArgs, args)) // trick to cut down on tree copying
413
414
typedArgs = args.asInstanceOf [List [Tree ]]
414
- methodType.instantiate( typedArgs.tpes )
415
+ assignType(app0, normalizedFun, typedArgs)
415
416
}
416
- wrapDefs(liftedDefs, cpy. Apply (app, normalizedFun, typedArgs).withType(ownType) )
417
+ wrapDefs(liftedDefs, app1 )
417
418
}
418
419
}
419
420
@@ -513,21 +514,11 @@ trait Applications extends Compatibility { self: Typer =>
513
514
def typedTypeApply (tree : untpd.TypeApply , pt : Type )(implicit ctx : Context ): Tree = track(" typedTypeApply" ) {
514
515
val typedArgs = tree.args mapconserve (typedType(_))
515
516
val typedFn = typedExpr(tree.fun, PolyProto (typedArgs.tpes, pt))
516
- val ownType = typedFn.tpe.widen match {
517
- case pt : PolyType =>
518
- checkBounds(typedArgs, pt, tree.pos)
519
- val argTypes = typedArgs.tpes
520
- if (argTypes.length == pt.paramNames.length)
521
- pt.resultType.substParams(pt, typedArgs.tpes)
522
- else {
523
- ctx.error(i " wrong number of type parameters for ${typedFn.tpe}; expected: ${pt.paramNames.length}" , tree.pos)
524
- ErrorType
525
- }
517
+ typedFn.tpe.widen match {
518
+ case pt : PolyType => checkBounds(typedArgs, pt, tree.pos)
526
519
case _ =>
527
- ctx.error(s " ${err.exprStr(typedFn)} does not take type parameters " , tree.pos)
528
- ErrorType
529
520
}
530
- cpy.TypeApply (tree, typedFn, typedArgs).withType(ownType )
521
+ assignType( cpy.TypeApply (tree, typedFn, typedArgs), typedFn, typedArgs )
531
522
}
532
523
533
524
def typedUnApply (tree : untpd.Apply , pt : Type )(implicit ctx : Context ): Tree = track(" typedUnApply" ) {
@@ -577,13 +568,13 @@ trait Applications extends Compatibility { self: Typer =>
577
568
/** Produce a typed qual.unappy or qual.unappySeq tree, or
578
569
* else if this fails follow a type alias and try again.
579
570
*/
580
- val unapply = trySelectUnapply(qual) { sel =>
571
+ val unapplyFn = trySelectUnapply(qual) { sel =>
581
572
val qual1 = followTypeAlias(qual)
582
573
if (qual1.isEmpty) notAnExtractor(sel)
583
574
else trySelectUnapply(qual1)(_ => notAnExtractor(sel))
584
575
}
585
576
586
- def fromScala2x = unapply .symbol.exists && (unapply .symbol.owner is Scala2x )
577
+ def fromScala2x = unapplyFn .symbol.exists && (unapplyFn .symbol.owner is Scala2x )
587
578
588
579
def unapplyArgs (unapplyResult : Type )(implicit ctx : Context ): List [Type ] = {
589
580
def extractorMemberType (tp : Type , name : Name ) = {
@@ -609,7 +600,7 @@ trait Applications extends Compatibility { self: Typer =>
609
600
// println(s"unapply $unapplyResult ${extractorMemberType(unapplyResult, nme.isDefined)}")
610
601
if (extractorMemberType(unapplyResult, nme.isDefined) isRef defn.BooleanClass ) {
611
602
if (getTp.exists)
612
- if (unapply .symbol.name == nme.unapplySeq) {
603
+ if (unapplyFn .symbol.name == nme.unapplySeq) {
613
604
val seqArg = boundsToHi(getTp.firstBaseArgInfo(defn.SeqClass ))
614
605
if (seqArg.exists) return args map Function .const(seqArg)
615
606
}
@@ -634,7 +625,7 @@ trait Applications extends Compatibility { self: Typer =>
634
625
case _ => false
635
626
}
636
627
637
- unapply .tpe.widen match {
628
+ unapplyFn .tpe.widen match {
638
629
case mt : MethodType if mt.paramTypes.length == 1 && ! mt.isDependent =>
639
630
val unapplyArgType = mt.paramTypes.head
640
631
unapp.println(s " unapp arg tpe = ${unapplyArgType.show}, pt = ${pt.show}" )
@@ -661,7 +652,7 @@ trait Applications extends Compatibility { self: Typer =>
661
652
// can open unsoundness holes. See SI-7952 for an example of the hole this opens.
662
653
if (ctx.settings.verbose.value) ctx.warning(msg, tree.pos)
663
654
} else {
664
- unapp.println(s " ${unapply .symbol.owner} ${unapply .symbol.owner is Scala2x }" )
655
+ unapp.println(s " ${unapplyFn .symbol.owner} ${unapplyFn .symbol.owner is Scala2x }" )
665
656
ctx.error(msg, tree.pos)
666
657
}
667
658
case _ =>
@@ -677,7 +668,7 @@ trait Applications extends Compatibility { self: Typer =>
677
668
}
678
669
679
670
val dummyArg = dummyTreeOfType(unapplyArgType)
680
- val unapplyApp = typedExpr(untpd.TypedSplice (Apply (unapply , dummyArg :: Nil )))
671
+ val unapplyApp = typedExpr(untpd.TypedSplice (Apply (unapplyFn , dummyArg :: Nil )))
681
672
val unapplyImplicits = unapplyApp match {
682
673
case Apply (Apply (unapply, `dummyArg` :: Nil ), args2) => assert(args2.nonEmpty); args2
683
674
case Apply (unapply, `dummyArg` :: Nil ) => Nil
@@ -695,12 +686,12 @@ trait Applications extends Compatibility { self: Typer =>
695
686
List .fill(argTypes.length - args.length)(WildcardType )
696
687
}
697
688
val unapplyPatterns = (bunchedArgs, argTypes).zipped map (typed(_, _))
698
- val result = cpy.UnApply (tree, unapply , unapplyImplicits, unapplyPatterns) withType ownType
689
+ val result = assignType( cpy.UnApply (tree, unapplyFn , unapplyImplicits, unapplyPatterns), ownType)
699
690
unapp.println(s " unapply patterns = $unapplyPatterns" )
700
691
if ((ownType eq pt) || ownType.isError) result
701
692
else Typed (result, TypeTree (ownType))
702
693
case tp =>
703
- val unapplyErr = if (tp.isError) unapply else notAnExtractor(unapply )
694
+ val unapplyErr = if (tp.isError) unapplyFn else notAnExtractor(unapplyFn )
704
695
val typedArgsErr = args mapconserve (typed(_, defn.AnyType ))
705
696
cpy.UnApply (tree, unapplyErr, Nil , typedArgsErr) withType ErrorType
706
697
}
0 commit comments