Skip to content

Commit bea77a7

Browse files
authored
Merge pull request #3183 from dotty-staging/fix-3179
fix #3179: bind should be nested in the plan for body
2 parents b78c050 + 635d7a7 commit bea77a7

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,12 +308,12 @@ object PatternMatcher {
308308
if (scrutinee.info.isNotNull || nonNull(scrutinee)) unappPlan
309309
else TestPlan(NonNullTest, scrutinee, tree.pos, unappPlan, onFailure)
310310
case Bind(name, body) =>
311-
val body1 = patternPlan(scrutinee, body, onSuccess, onFailure)
312-
if (name == nme.WILDCARD) body1
311+
if (name == nme.WILDCARD) patternPlan(scrutinee, body, onSuccess, onFailure)
313312
else {
313+
// The type of `name` may refer to val in `body`, therefore should come after `body`
314314
val bound = tree.symbol.asTerm
315315
initializer(bound) = ref(scrutinee)
316-
LetPlan(bound, body1)
316+
patternPlan(scrutinee, body, LetPlan(bound, onSuccess), onFailure)
317317
}
318318
case Alternative(alts) =>
319319
labelAbstract(onSuccess) { ons =>

tests/run/3179.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
object Test {
2+
def main(args: Array[String]): Unit = {
3+
("": Any) match {
4+
case a @ Test => 1
5+
case _ => 2
6+
}
7+
}
8+
}

0 commit comments

Comments
 (0)