From 11cc9c18162e952195235e8a29cc0232460989d7 Mon Sep 17 00:00:00 2001 From: Martijn Hoekstra Date: Tue, 1 Dec 2020 11:13:53 +0100 Subject: [PATCH] make literal true extractors irrefutable --- .../tools/nsc/transform/patmat/MatchAnalysis.scala | 10 +++++----- test/files/pos/{t12232_.scala => t12254.scala} | 3 +++ 2 files changed, 8 insertions(+), 5 deletions(-) rename test/files/pos/{t12232_.scala => t12254.scala} (75%) diff --git a/src/compiler/scala/tools/nsc/transform/patmat/MatchAnalysis.scala b/src/compiler/scala/tools/nsc/transform/patmat/MatchAnalysis.scala index 7da5e5e82bd8..89d12b2ec6cb 100644 --- a/src/compiler/scala/tools/nsc/transform/patmat/MatchAnalysis.scala +++ b/src/compiler/scala/tools/nsc/transform/patmat/MatchAnalysis.scala @@ -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] = { diff --git a/test/files/pos/t12232_.scala b/test/files/pos/t12254.scala similarity index 75% rename from test/files/pos/t12232_.scala rename to test/files/pos/t12254.scala index 098b62b565f3..a44393063d60 100644 --- a/test/files/pos/t12232_.scala +++ b/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