Skip to content

Commit e4eb3fe

Browse files
committed
Fix #4935: remove unsound optimization
1 parent 35c01fe commit e4eb3fe

File tree

4 files changed

+9
-13
lines changed

4 files changed

+9
-13
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -921,9 +921,7 @@ object desugar {
921921
}
922922
val ids = for ((named, _) <- vars) yield Ident(named.name)
923923
val caseDef = CaseDef(pat, EmptyTree, makeTuple(ids))
924-
val matchExpr =
925-
if (forallResults(rhs, isMatchingTuple)) rhs
926-
else Match(rhsUnchecked, caseDef :: Nil)
924+
val matchExpr = Match(rhsUnchecked, caseDef :: Nil)
927925
vars match {
928926
case Nil =>
929927
matchExpr

compiler/src/dotty/tools/dotc/ast/TreeInfo.scala

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -269,16 +269,6 @@ trait TreeInfo[T >: Untyped <: Type] { self: Trees.Instance[T] =>
269269
*/
270270
def bodyKind(body: List[Tree])(implicit ctx: Context): FlagSet =
271271
(NoInitsInterface /: body)((fs, stat) => fs & defKind(stat))
272-
273-
/** Checks whether predicate `p` is true for all result parts of this expression,
274-
* where we zoom into Ifs, Matches, and Blocks.
275-
*/
276-
def forallResults(tree: Tree, p: Tree => Boolean): Boolean = tree match {
277-
case If(_, thenp, elsep) => forallResults(thenp, p) && forallResults(elsep, p)
278-
case Match(_, cases) => cases forall (c => forallResults(c.body, p))
279-
case Block(_, expr) => forallResults(expr, p)
280-
case _ => p(tree)
281-
}
282272
}
283273

284274
trait UntypedTreeInfo extends TreeInfo[Untyped] { self: Trees.Instance[Untyped] =>

tests/neg/i4935.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, B) = () // error // error
3+
}

tests/run/i4935.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
object Test {
2+
val (Some(a), b) = (Some(3), 6)
3+
4+
def main(args: Array[String]) = assert(a == 3)
5+
}

0 commit comments

Comments
 (0)