Skip to content
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

Fix #11541: Specialize ClassTag[T] in exhaustivity check #17385

Merged
merged 1 commit into from
May 4, 2023
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
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,7 @@ class Definitions {

@tu lazy val ReflectPackageClass: Symbol = requiredPackage("scala.reflect.package").moduleClass
@tu lazy val ClassTagClass: ClassSymbol = requiredClass("scala.reflect.ClassTag")
@tu lazy val ClassTagClass_unapply: Symbol = ClassTagClass.requiredMethod("unapply")
@tu lazy val ClassTagModule: Symbol = ClassTagClass.companionModule
@tu lazy val ClassTagModule_apply: Symbol = ClassTagModule.requiredMethod(nme.apply)

Expand Down
7 changes: 6 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/patmat/Space.scala
Original file line number Diff line number Diff line change
Expand Up @@ -602,10 +602,15 @@ object SpaceEngine {

/** Whether the extractor covers the given type */
def covers(unapp: TermRef, scrutineeTp: Type, argLen: Int)(using Context): Boolean =
SpaceEngine.isIrrefutable(unapp, argLen) || unapp.symbol == defn.TypeTest_unapply && {
SpaceEngine.isIrrefutable(unapp, argLen)
|| unapp.symbol == defn.TypeTest_unapply && {
val AppliedType(_, _ :: tp :: Nil) = unapp.prefix.widen.dealias: @unchecked
scrutineeTp <:< tp
}
|| unapp.symbol == defn.ClassTagClass_unapply && {
val AppliedType(_, tp :: Nil) = unapp.prefix.widen.dealias: @unchecked
scrutineeTp <:< tp
}

/** Decompose a type into subspaces -- assume the type can be decomposed */
def decompose(tp: Type)(using Context): List[Type] = trace(i"decompose($tp)", debug) {
Expand Down
13 changes: 13 additions & 0 deletions tests/patmat/i11541.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import scala.reflect.ClassTag

class Test:
type A

given ClassTag[A] = ???

var a: A | Null = null

a match { //WARNING: match may not be exhaustive. It would fail on pattern case: _: A
case null =>
case a: A =>
}