Skip to content

Commit

Permalink
bugfix: Remove incorrect synthetic decorations in partial functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jkciesluk authored and tgodzik committed Nov 24, 2023
1 parent 2c55cb2 commit f905aa4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}

0 comments on commit f905aa4

Please sign in to comment.