@@ -388,31 +388,35 @@ object TreeChecker {
388388 }
389389
390390 override def typedUnadapted (tree : untpd.Tree , pt : Type , locked : TypeVars )(using Context ): Tree = {
391- val res = tree match {
392- case _ : untpd.TypedSplice | _ : untpd.Thicket | _ : EmptyValDef [? ] =>
393- super .typedUnadapted(tree, pt, locked)
394- case _ if tree.isType =>
395- promote(tree)
396- case _ =>
397- val tree1 = super .typedUnadapted(tree, pt, locked)
398- def isSubType (tp1 : Type , tp2 : Type ) =
399- (tp1 eq tp2) || // accept NoType / NoType
400- (tp1 <:< tp2)
401- def divergenceMsg (tp1 : Type , tp2 : Type ) =
402- s """ Types differ
403- |Original type : ${tree.typeOpt.show}
404- |After checking: ${tree1.tpe.show}
405- |Original tree : ${tree.show}
406- |After checking: ${tree1.show}
407- |Why different :
408- """ .stripMargin + core.TypeComparer .explained(_.isSubType(tp1, tp2))
409- if (tree.hasType) // it might not be typed because Typer sometimes constructs new untyped trees and resubmits them to typedUnadapted
410- assert(isSubType(tree1.tpe, tree.typeOpt), divergenceMsg(tree1.tpe, tree.typeOpt))
411- tree1
412- }
413- checkNoOrphans(res.tpe)
414- phasesToCheck.foreach(_.checkPostCondition(res))
415- res
391+ try
392+ val res = tree match
393+ case _ : untpd.TypedSplice | _ : untpd.Thicket | _ : EmptyValDef [? ] =>
394+ super .typedUnadapted(tree, pt, locked)
395+ case _ if tree.isType =>
396+ promote(tree)
397+ case _ =>
398+ val tree1 = super .typedUnadapted(tree, pt, locked)
399+ def isSubType (tp1 : Type , tp2 : Type ) =
400+ (tp1 eq tp2) || // accept NoType / NoType
401+ (tp1 <:< tp2)
402+ def divergenceMsg (tp1 : Type , tp2 : Type ) =
403+ s """ Types differ
404+ |Original type : ${tree.typeOpt.show}
405+ |After checking: ${tree1.tpe.show}
406+ |Original tree : ${tree.show}
407+ |After checking: ${tree1.show}
408+ |Why different :
409+ """ .stripMargin + core.TypeComparer .explained(_.isSubType(tp1, tp2))
410+ if (tree.hasType) // it might not be typed because Typer sometimes constructs new untyped trees and resubmits them to typedUnadapted
411+ assert(isSubType(tree1.tpe, tree.typeOpt), divergenceMsg(tree1.tpe, tree.typeOpt))
412+ tree1
413+ checkNoOrphans(res.tpe)
414+ phasesToCheck.foreach(_.checkPostCondition(res))
415+ res
416+ catch case NonFatal (ex) if ! ctx.run.enrichedErrorMessage =>
417+ val treeStr = tree.show(using ctx.withPhase(ctx.phase.prev.megaPhase))
418+ println(ctx.run.enrichErrorMessage(s " exception while retyping $treeStr of class ${tree.className} # ${tree.uniqueId}" ))
419+ throw ex
416420 }
417421
418422 def checkNotRepeated (tree : Tree )(using Context ): tree.type = {
0 commit comments