Skip to content

fix #3179: bind should be nested in the plan for body #3183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala
Original file line number Diff line number Diff line change
Expand Up @@ -308,12 +308,12 @@ object PatternMatcher {
if (scrutinee.info.isNotNull || nonNull(scrutinee)) unappPlan
else TestPlan(NonNullTest, scrutinee, tree.pos, unappPlan, onFailure)
case Bind(name, body) =>
val body1 = patternPlan(scrutinee, body, onSuccess, onFailure)
if (name == nme.WILDCARD) body1
if (name == nme.WILDCARD) patternPlan(scrutinee, body, onSuccess, onFailure)
else {
// The type of `name` may refer to val in `body`, therefore should come after `body`
val bound = tree.symbol.asTerm
initializer(bound) = ref(scrutinee)
LetPlan(bound, body1)
patternPlan(scrutinee, body, LetPlan(bound, onSuccess), onFailure)
}
case Alternative(alts) =>
labelAbstract(onSuccess) { ons =>
Expand Down
8 changes: 8 additions & 0 deletions tests/run/3179.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
object Test {
def main(args: Array[String]): Unit = {
("": Any) match {
case a @ Test => 1
case _ => 2
}
}
}