From f905aa43ef46b94a51e134889aa1c1ca2475167c Mon Sep 17 00:00:00 2001 From: Jakub Ciesluk <323892@uwr.edu.pl> Date: Fri, 24 Nov 2023 09:26:08 +0100 Subject: [PATCH] bugfix: Remove incorrect synthetic decorations in partial functions --- .../pc/PcSyntheticDecorationsProvider.scala | 11 +++++++++-- .../tests/pc/SyntheticDecorationsSuite.scala | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/mtags/src/main/scala-2/scala/meta/internal/pc/PcSyntheticDecorationsProvider.scala b/mtags/src/main/scala-2/scala/meta/internal/pc/PcSyntheticDecorationsProvider.scala index dfbc95b0a34..42fb9bb68dd 100644 --- a/mtags/src/main/scala-2/scala/meta/internal/pc/PcSyntheticDecorationsProvider.scala +++ b/mtags/src/main/scala-2/scala/meta/internal/pc/PcSyntheticDecorationsProvider.scala @@ -157,9 +157,11 @@ final class PcSyntheticDecorationsProvider( case dd @ DefDef(_, _, _, _, tpt, _) if hasMissingTypeAnnot(dd, tpt) && !dd.symbol.isConstructor && - !dd.symbol.isMutable => + !dd.symbol.isMutable && + !samePosAsOwner(dd.symbol) => Some(dd.symbol.tpe.widen.finalResultType, findTpePos(dd)) - case bb @ Bind(name, Ident(nme.WILDCARD)) if name != nme.WILDCARD => + case bb @ Bind(name, Ident(nme.WILDCARD)) + if name != nme.WILDCARD && name != nme.DEFAULT_CASE => Some(bb.symbol.tpe.widen.finalResultType, bb.namePosition) case _ => None } @@ -169,6 +171,11 @@ final class PcSyntheticDecorationsProvider( private def primaryConstructorParam(sym: Symbol) = sym.safeOwner.isPrimaryConstructor + private def samePosAsOwner(sym: Symbol) = { + val owner = sym.safeOwner + sym.pos == owner.pos + } + private def findTpePos(dd: DefDef) = { if (dd.rhs.isEmpty) dd.pos else { diff --git a/tests/cross/src/test/scala/tests/pc/SyntheticDecorationsSuite.scala b/tests/cross/src/test/scala/tests/pc/SyntheticDecorationsSuite.scala index 105e3f352d2..d43b38059c7 100644 --- a/tests/cross/src/test/scala/tests/pc/SyntheticDecorationsSuite.scala +++ b/tests/cross/src/test/scala/tests/pc/SyntheticDecorationsSuite.scala @@ -548,4 +548,22 @@ class SyntheticDecorationsSuite extends BaseSyntheticDecorationsSuite { |} |""".stripMargin ) + + check( + "partial-fun".tag(IgnoreScalaVersion.forLessThan("2.13.0")), + """|object Main { + | List(1).collect { case x => x } + | val x: PartialFunction[Int, Int] = { + | case 1 => 2 + | } + |} + |""".stripMargin, + """|object Main { + | List[Int](1).collect[Int] { case x: Int => x } + | val x: PartialFunction[Int, Int] = { + | case 1 => 2 + | } + |} + |""".stripMargin + ) }