Skip to content

Commit

Permalink
make literal true extractors irrefutable
Browse files Browse the repository at this point in the history
  • Loading branch information
martijnhoekstra committed Dec 1, 2020
1 parent 69d44d3 commit 1f83070
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Expand Up @@ -390,13 +390,13 @@ trait MatchApproximation extends TreeAndTypeAnalysis with ScalaLogic with MatchT
// note: this assumes the other side-conditions implied by the extractor are met
// (argument of the right type, length check succeeds for unapplySeq,...)
private def irrefutableExtractorType(tp: Type): Boolean = tp.resultType.dealias match {
//Some(x) is always irrefutable
//Some(x) is irrefutable
case TypeRef(_, SomeClass, _) => true
//name based pattern matching checks for constant false `isEmpty`.
case TypeRef(_, res, _) => res.tpe.members.exists(isIrrefutabilityProof)
// probably not useful since this type won't be inferred nor can it be written down (yet)
case ConstantTrue => true
case _ => false
case TypeRef(_, res, _) => res.tpe.members.exists(isIrrefutabilityProof)
//`true.type` is irrefutable for boolean extractors
case c: ConstantType => c.value == Constant(true)
case _ => false
}

private val irrefutableExtractor: PartialFunction[TreeMaker, Prop] = {
Expand Down
3 changes: 3 additions & 0 deletions test/files/pos/t12232_.scala → test/files/pos/t12254.scala
@@ -1,3 +1,6 @@
// scalac: -Xfatal-warnings -Xlint:strict-unsealed-patmat
//

object Test {
sealed trait Foo
final class Bar extends Foo
Expand Down

0 comments on commit 1f83070

Please sign in to comment.