Skip to content

Fix #9489: skip redundancy check for Type[T] #9501

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions compiler/src/dotty/tools/dotc/transform/patmat/Space.scala
Original file line number Diff line number Diff line change
Expand Up @@ -839,12 +839,14 @@ class SpaceEngine(using Context) extends SpaceLogic {
}

private def redundancyCheckable(sel: Tree): Boolean =
// Ignore Expr for unreachability as a special case.
// Ignore Expr[T] and Type[T] for unreachability as a special case.
// Quote patterns produce repeated calls to the same unapply method, but with different implicit parameters.
// Since we assume that repeated calls to the same unapply method overlap
// and implicit parameters cannot normally differ between two patterns in one `match`,
// the easiest solution is just to ignore Expr.
!sel.tpe.hasAnnotation(defn.UncheckedAnnot) && !sel.tpe.widen.isRef(defn.QuotedExprClass)
// the easiest solution is just to ignore Expr[T] and Type[T].
!sel.tpe.hasAnnotation(defn.UncheckedAnnot)
&& !sel.tpe.widen.isRef(defn.QuotedExprClass)
&& !sel.tpe.widen.isRef(defn.QuotedTypeClass)

def checkRedundancy(_match: Match): Unit = {
val Match(sel, cases) = _match
Expand Down
7 changes: 7 additions & 0 deletions tests/patmat/i9489.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import scala.quoted._

def summonTypedType[T : Type](using QuoteContext): String = '[T] match {
case '[Boolean] => "Boolean"
case '[Byte] => "Byte"
case _ => "Other"
}