@@ -432,19 +432,8 @@ object TreeChecker {
432432 promote(tree)
433433 case _ =>
434434 val tree1 = super .typedUnadapted(tree, pt, locked)
435- def isSubType (tp1 : Type , tp2 : Type ) =
436- (tp1 eq tp2) || // accept NoType / NoType
437- (tp1 <:< tp2)
438- def divergenceMsg (tp1 : Type , tp2 : Type ) =
439- s """ Types differ
440- |Original type : ${tree.typeOpt.show}
441- |After checking: ${tree1.tpe.show}
442- |Original tree : ${tree.show}
443- |After checking: ${tree1.show}
444- |Why different :
445- """ .stripMargin + core.TypeComparer .explained(_.isSubType(tp1, tp2))
446- if (tree.hasType) // it might not be typed because Typer sometimes constructs new untyped trees and resubmits them to typedUnadapted
447- assert(isSubType(tree1.tpe, tree.typeOpt), divergenceMsg(tree1.tpe, tree.typeOpt))
435+ if tree.hasType then // it might not be typed because Typer sometimes constructs new untyped trees and resubmits them to typedUnadapted
436+ checkType(tree1.tpe, tree.typeOpt, tree, " typedUnadapted" )
448437 tree1
449438 checkNoOrphans(res.tpe)
450439 phasesToCheck.foreach(_.checkPostCondition(res))
@@ -824,16 +813,20 @@ object TreeChecker {
824813 && ! isPrimaryConstructorReturn
825814 && ! pt.isInstanceOf [FunOrPolyProto ]
826815 then
827- assert(tree.tpe <:< pt, {
828- val mismatch = TypeMismatch (tree.tpe, pt, Some (tree))
829- i """ |Type Mismatch:
830- | ${mismatch.message}
831- |tree = $tree ${tree.className}""" .stripMargin
832- })
816+ checkType(tree.tpe, pt, tree, " adapt" )
833817 tree
834818 }
835819
836820 override def simplify (tree : Tree , pt : Type , locked : TypeVars )(using Context ): tree.type = tree
821+
822+ private def checkType (tp1 : Type , tp2 : Type , tree : untpd.Tree , step : String )(using Context ) =
823+ // Accept NoType <:< NoType as true
824+ assert((tp1 eq tp2) || (tp1 <:< tp2), {
825+ val mismatch = TypeMismatch (tp1, tp2, None )
826+ i """ |Type Mismatch (while checking $step):
827+ | ${mismatch.message}${mismatch.explanation}
828+ |tree = $tree ${tree.className}""" .stripMargin
829+ })
837830 }
838831
839832 /** Tree checker that can be applied to a local tree. */
0 commit comments