diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/extensions/ParenthesizedElement.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/extensions/ParenthesizedElement.scala index d0140357e0f..3701db54646 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/extensions/ParenthesizedElement.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/extensions/ParenthesizedElement.scala @@ -199,10 +199,13 @@ object ParenthesizedElement { /* * Parenthesis here are not redundant * test { blub: (Int => Int) => ??? } + * case _: (String => String) => // SCL-21577 */ def unapply(p: ScParenthesisedTypeElement): Boolean = - p.innerElement.exists(_.is[ScFunctionalTypeElement]) && - p.getParent.is[ScParameterType] && - p.nextVisibleLeaf.exists(_.elementType == ScalaTokenTypes.tFUNTYPE) + p.innerElement.exists(_.is[ScFunctionalTypeElement]) && ( + (p.getParent.is[ScParameterType] && + p.nextVisibleLeaf.exists(_.elementType == ScalaTokenTypes.tFUNTYPE)) || + p.getParent.is[ScTypePattern] + ) } } diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/codeInspection/parentheses/ScalaUnnecessaryParenthesesInspectionTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/codeInspection/parentheses/ScalaUnnecessaryParenthesesInspectionTest.scala index 7103017da1c..8b0b7144131 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/codeInspection/parentheses/ScalaUnnecessaryParenthesesInspectionTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/codeInspection/parentheses/ScalaUnnecessaryParenthesesInspectionTest.scala @@ -680,4 +680,15 @@ class ScalaUnnecessaryParenthesesInspectionTest_Scala3 extends ScalaUnnecessaryP checkTextHasErrors(s"val $START((x = _, y = _))$END = ???") checkTextHasErrors(s"val (x = _, y = $START(_)$END) = ???") } + + def testSCL21577_FunctionTypeInPattern(): Unit = { + checkTextHasNoErrors( + """ + |null match { + | case _: (String => String) => + | case _ => + |} + """.stripMargin + ) + } }