From 3cc4837a319bad225ca2f13ecc9eab57ad65b26d Mon Sep 17 00:00:00 2001
From: "Paolo G. Giarrusso"
Date: Sat, 25 Aug 2018 01:18:50 +0200
Subject: [PATCH 1/2] Fix #4999: allow pattern matching against by-name
arguments
In this testcase `tp` is `TermRef(NoPrefix, xs)` so widenExpr does nothing, but
`widenTermRefExpr` is appropriate.
---
.../src/dotty/tools/dotc/transform/PatternMatcher.scala | 2 +-
tests/pos/i4999.scala | 9 +++++++++
2 files changed, 10 insertions(+), 1 deletion(-)
create mode 100644 tests/pos/i4999.scala
diff --git a/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala b/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala
index ebaca5b626b1..5e8d114c2222 100644
--- a/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala
+++ b/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala
@@ -116,7 +116,7 @@ object PatternMatcher {
/** Widen type as far as necessary so that it does not refer to a pattern-
* generated variable.
*/
- private def sanitize(tp: Type): Type = tp.widenExpr match {
+ private def sanitize(tp: Type): Type = tp.widenTermRefExpr match {
case tp: TermRef if refersToInternal(false, tp) => sanitize(tp.underlying)
case tp => tp
}
diff --git a/tests/pos/i4999.scala b/tests/pos/i4999.scala
new file mode 100644
index 000000000000..b7a856bf296a
--- /dev/null
+++ b/tests/pos/i4999.scala
@@ -0,0 +1,9 @@
+trait Foo
+final class Bar extends Foo
+
+class Test {
+ def test(xs: => Foo) = xs match {
+ case xs: Bar => 1
+ case _ => 2
+ }
+}
From bfb716ff881acb1161d4f7e9f17ece21a85b8bf4 Mon Sep 17 00:00:00 2001
From: "Paolo G. Giarrusso"
Date: Sat, 25 Aug 2018 01:31:27 +0200
Subject: [PATCH 2/2] Don't widen stable scrutinee types
Since ExprType are unstable, we can keep stable TermRef alone, in case
this provides more info to the pattern matcher/exhaustivity checker.
---
compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala b/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala
index 5e8d114c2222..a203584f27fe 100644
--- a/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala
+++ b/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala
@@ -116,7 +116,7 @@ object PatternMatcher {
/** Widen type as far as necessary so that it does not refer to a pattern-
* generated variable.
*/
- private def sanitize(tp: Type): Type = tp.widenTermRefExpr match {
+ private def sanitize(tp: Type): Type = tp.widenIfUnstable match {
case tp: TermRef if refersToInternal(false, tp) => sanitize(tp.underlying)
case tp => tp
}