From 8878f3177ffe1933acbb94fd4996ca231b739796 Mon Sep 17 00:00:00 2001 From: Tom Grigg Date: Sun, 29 May 2022 10:24:58 -0700 Subject: [PATCH] Fix rewrite for type-ascribed refutable pattern binding --- compiler/src/dotty/tools/dotc/typer/Typer.scala | 3 ++- tests/rewrites/refutable-pattern-bindings.check | 2 ++ tests/rewrites/refutable-pattern-bindings.scala | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index eb0b92358db8..a0058233588a 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -1598,7 +1598,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer | _: untpd.Match | _: untpd.ForYield | _: untpd.ParsedTry - | _: untpd.Try => Some("(", ")") + | _: untpd.Try + | _: untpd.Typed => Some("(", ")") case _: untpd.Block => Some("{", "}") case _ => None diff --git a/tests/rewrites/refutable-pattern-bindings.check b/tests/rewrites/refutable-pattern-bindings.check index 5acea5dc0ead..de61b29ebdf7 100644 --- a/tests/rewrites/refutable-pattern-bindings.check +++ b/tests/rewrites/refutable-pattern-bindings.check @@ -23,3 +23,5 @@ val j :: k = (for case (x: String) <- xs yield x): @unchecked + +val (_: Int | _: AnyRef) = (??? : AnyRef): @unchecked diff --git a/tests/rewrites/refutable-pattern-bindings.scala b/tests/rewrites/refutable-pattern-bindings.scala index e724c9564bd2..eb796662e207 100644 --- a/tests/rewrites/refutable-pattern-bindings.scala +++ b/tests/rewrites/refutable-pattern-bindings.scala @@ -23,3 +23,5 @@ val j :: k = for (x: String) <- xs yield x + +val (_: Int | _: AnyRef) = ??? : AnyRef