Skip to content

Commit 3cc4837

Browse files
committed
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.
1 parent 67e2b6a commit 3cc4837

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ object PatternMatcher {
116116
/** Widen type as far as necessary so that it does not refer to a pattern-
117117
* generated variable.
118118
*/
119-
private def sanitize(tp: Type): Type = tp.widenExpr match {
119+
private def sanitize(tp: Type): Type = tp.widenTermRefExpr match {
120120
case tp: TermRef if refersToInternal(false, tp) => sanitize(tp.underlying)
121121
case tp => tp
122122
}

tests/pos/i4999.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
trait Foo
2+
final class Bar extends Foo
3+
4+
class Test {
5+
def test(xs: => Foo) = xs match {
6+
case xs: Bar => 1
7+
case _ => 2
8+
}
9+
}

0 commit comments

Comments
 (0)