@@ -397,19 +397,8 @@ object TreeChecker {
397
397
promote(tree)
398
398
case _ =>
399
399
val tree1 = super .typedUnadapted(tree, pt, locked)
400
- def isSubType (tp1 : Type , tp2 : Type ) =
401
- (tp1 eq tp2) || // accept NoType / NoType
402
- (tp1 <:< tp2)
403
- def divergenceMsg (tp1 : Type , tp2 : Type ) =
404
- s """ Types differ
405
- |Original type : ${tree.typeOpt.show}
406
- |After checking: ${tree1.tpe.show}
407
- |Original tree : ${tree.show}
408
- |After checking: ${tree1.show}
409
- |Why different :
410
- """ .stripMargin + core.TypeComparer .explained(_.isSubType(tp1, tp2))
411
- if (tree.hasType) // it might not be typed because Typer sometimes constructs new untyped trees and resubmits them to typedUnadapted
412
- assert(isSubType(tree1.tpe, tree.typeOpt), divergenceMsg(tree1.tpe, tree.typeOpt))
400
+ if tree.hasType then // it might not be typed because Typer sometimes constructs new untyped trees and resubmits them to typedUnadapted
401
+ checkType(tree1.tpe, tree.typeOpt, tree, " typedUnadapted" )
413
402
tree1
414
403
checkNoOrphans(res.tpe)
415
404
phasesToCheck.foreach(_.checkPostCondition(res))
@@ -747,28 +736,25 @@ object TreeChecker {
747
736
override def adapt (tree : Tree , pt : Type , locked : TypeVars )(using Context ): Tree = {
748
737
def isPrimaryConstructorReturn =
749
738
ctx.owner.isPrimaryConstructor && pt.isRef(ctx.owner.owner) && tree.tpe.isRef(defn.UnitClass )
750
- def infoStr (tp : Type ) = tp match {
751
- case tp : TypeRef =>
752
- val sym = tp.symbol
753
- i " ${sym.showLocated} with ${tp.designator}, flags = ${sym.flagsString}, underlying = ${tp.underlyingIterator.toList}%, % "
754
- case _ =>
755
- " ??"
756
- }
757
- if (ctx.mode.isExpr &&
758
- ! tree.isEmpty &&
759
- ! isPrimaryConstructorReturn &&
760
- ! pt.isInstanceOf [FunOrPolyProto ])
761
- assert(tree.tpe <:< pt, {
762
- val mismatch = TypeMismatch (tree.tpe, pt, Some (tree))
763
- i """ | ${mismatch.msg}
764
- |found: ${infoStr(tree.tpe)}
765
- |expected: ${infoStr(pt)}
766
- |tree = $tree""" .stripMargin
767
- })
739
+ if ctx.mode.isExpr
740
+ && ! tree.isEmpty
741
+ && ! isPrimaryConstructorReturn
742
+ && ! pt.isInstanceOf [FunOrPolyProto ]
743
+ then
744
+ checkType(tree.tpe, pt, tree, " adapt" )
768
745
tree
769
746
}
770
747
771
748
override def simplify (tree : Tree , pt : Type , locked : TypeVars )(using Context ): tree.type = tree
749
+
750
+ private def checkType (tp1 : Type , tp2 : Type , tree : untpd.Tree , step : String )(using Context ) =
751
+ // Accept NoType <:< NoType as true
752
+ assert((tp1 eq tp2) || (tp1 <:< tp2), {
753
+ val mismatch = TypeMismatch (tp1, tp2, None )
754
+ i """ |Type Mismatch (while checking $step):
755
+ | ${mismatch.message}${mismatch.explanation}
756
+ |tree = $tree ${tree.className}""" .stripMargin
757
+ })
772
758
}
773
759
774
760
/** Tree checker that can be applied to a local tree. */
0 commit comments