Skip to content

Commit 0c21d4c

Browse files
authored
Merge pull request #5012 from dotty-staging/fix-4999-pattern-match-byref
Fix #4999: allow pattern matching against by-name arguments
2 parents eda6b0c + bfb716f commit 0c21d4c

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
@@ -117,7 +117,7 @@ object PatternMatcher {
117117
/** Widen type as far as necessary so that it does not refer to a pattern-
118118
* generated variable.
119119
*/
120-
private def sanitize(tp: Type): Type = tp.widenExpr match {
120+
private def sanitize(tp: Type): Type = tp.widenIfUnstable match {
121121
case tp: TermRef if refersToInternal(false, tp) => sanitize(tp.underlying)
122122
case tp => tp
123123
}

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)