From 5d2f10ed2e6f75502acd78505aca7f1876cfb266 Mon Sep 17 00:00:00 2001 From: Tom Grigg Date: Tue, 18 Jan 2022 15:33:01 -0800 Subject: [PATCH] Fix tests crashing under strict pattern binding warnings Before this commit, the tests listed below would crash when the stricter pattern binding rules were enforced (whether using `-source future` or now enabled by default) - neg/parser-stability-14.scala - neg/i4453.scala - fuzzy/CCE-aafcaa9cd2611d22f63273738d637f5bec6e7152.scala - fuzzy/comment3.scala with a common stack trace: dotty.tools.dotc.core.Types$PreviousErrorType cannot be cast to dotty.tools.dotc.core.Types$TermRef dotty.tools.dotc.transform.patmat.SpaceEngine$.isIrrefutable(Space.scala:316) dotty.tools.dotc.typer.Checking.recur$1(Checking.scala:828) dotty.tools.dotc.typer.Checking.checkIrrefutable(Checking.scala:843) dotty.tools.dotc.typer.Checking.checkIrrefutable$(Checking.scala:775) dotty.tools.dotc.typer.Typer.checkIrrefutable(Typer.scala:119) ... --- compiler/src/dotty/tools/dotc/transform/patmat/Space.scala | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala index 56a595780365..008198526999 100644 --- a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala +++ b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala @@ -312,9 +312,9 @@ object SpaceEngine { * @param unapp The unapply function tree */ def isIrrefutable(unapp: tpd.Tree, argLen: Int)(using Context): Boolean = { - val fun1 = tpd.funPart(unapp) - val funRef = fun1.tpe.asInstanceOf[TermRef] - isIrrefutable(funRef, argLen) + tpd.funPart(unapp).tpe match + case funRef: TermRef => isIrrefutable(funRef, argLen) + case _: ErrorType => false } }