Skip to content

Commit 17fe2b0

Browse files
authored
Merge pull request #11617 from dotty-staging/fix-11605
Constant fold results of nonempty tests in pattern matching
2 parents 96ced02 + 99130ff commit 17fe2b0

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -692,9 +692,10 @@ object PatternMatcher {
692692
val scrutinee = plan.scrutinee
693693
(plan.test: @unchecked) match {
694694
case NonEmptyTest =>
695-
scrutinee
696-
.select(nme.isEmpty, _.info.isParameterless)
697-
.select(nme.UNARY_!, _.info.isParameterless)
695+
constToLiteral(
696+
scrutinee
697+
.select(nme.isEmpty, _.info.isParameterless)
698+
.select(nme.UNARY_!, _.info.isParameterless))
698699
case NonNullTest =>
699700
scrutinee.testNotNull
700701
case GuardTest =>

tests/pos/i11605.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package example
2+
3+
class Extractor[A](val get: A) extends AnyVal {
4+
// https://github.com/scala/scala/pull/9343
5+
def isEmpty: false = false
6+
}
7+
8+
object Foo {
9+
def unapply(x: String): Extractor[String] = new Extractor(x)
10+
}
11+
12+
object Main {
13+
val Foo(a) = "a"
14+
}

0 commit comments

Comments
 (0)