Skip to content

Commit 5a5f9d7

Browse files
authored
Merge pull request #1452 from dotty-staging/fix-#1432
Fix desugaring of Bind(WILDCARD, _).
2 parents aaa32f7 + 0b2ddd0 commit 5a5f9d7

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,8 +1007,8 @@ object desugar {
10071007
def add(named: NameTree, t: Tree): Unit =
10081008
if (!seenName(named.name)) buf += ((named, t))
10091009
def collect(tree: Tree): Unit = tree match {
1010-
case Bind(nme.WILDCARD, _) =>
1011-
collect(tree)
1010+
case Bind(nme.WILDCARD, tree1) =>
1011+
collect(tree1)
10121012
case tree @ Bind(_, Typed(tree1, tpt)) if !mayBeTypePat(tpt) =>
10131013
add(tree, tpt)
10141014
collect(tree1)

tests/pos/i1432.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
object Foo {
2+
val _@a = 1 // This entered in an infinite loop
3+
}

tests/run/i1432.check

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Some(foo)
2+
foo

tests/run/i1432.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
object Test {
2+
3+
def main(args: Array[String]): Unit = {
4+
val someFoo = Some("foo")
5+
val _ @ bar = someFoo
6+
val _ @ Some(baz) = someFoo
7+
println(bar)
8+
println(baz)
9+
}
10+
11+
}

0 commit comments

Comments
 (0)