From 231c3a389365af7aa05b55971a8c17a571b42f7b Mon Sep 17 00:00:00 2001 From: Katarzyna Marek Date: Tue, 8 Aug 2023 16:58:31 +0200 Subject: [PATCH] bugfix: highlight enum cases correctly [Cherry-picked aca2503a9962929ece651239e534b96420a8532f] --- .../src/main/dotty/tools/pc/PcCollector.scala | 7 +++++++ .../highlight/DocumentHighlightSuite.scala | 20 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/presentation-compiler/src/main/dotty/tools/pc/PcCollector.scala b/presentation-compiler/src/main/dotty/tools/pc/PcCollector.scala index d8c68c6c49c8..1700c4e16197 100644 --- a/presentation-compiler/src/main/dotty/tools/pc/PcCollector.scala +++ b/presentation-compiler/src/main/dotty/tools/pc/PcCollector.scala @@ -194,6 +194,13 @@ abstract class PcCollector[T]( case (df: NamedDefTree) :: _ if df.nameSpan.contains(pos.span) && !isGeneratedGiven(df) => Some(symbolAlternatives(df.symbol), pos.withSpan(df.nameSpan)) + /* enum cases with params + * enum Foo: + * case B@@ar[A](i: A) + */ + case (df: NamedDefTree) :: Template(_, _, self, _) :: _ + if (df.name == nme.apply || df.name == nme.unapply) && df.nameSpan.isZeroExtent => + Some(symbolAlternatives(self.tpt.symbol), self.sourcePos) /** * For traversing annotations: * @JsonNo@@tification("") diff --git a/presentation-compiler/test/dotty/tools/pc/tests/highlight/DocumentHighlightSuite.scala b/presentation-compiler/test/dotty/tools/pc/tests/highlight/DocumentHighlightSuite.scala index ce24902c2e58..47a07c873a61 100644 --- a/presentation-compiler/test/dotty/tools/pc/tests/highlight/DocumentHighlightSuite.scala +++ b/presentation-compiler/test/dotty/tools/pc/tests/highlight/DocumentHighlightSuite.scala @@ -998,3 +998,23 @@ class DocumentHighlightSuite extends BaseDocumentHighlightSuite: | def double2(ys: List[EF]) = <> ++ ys |end extension""".stripMargin ) + + @Test def `enum-cases` = + check( + """|enum MyOption: + | case <>(value: Int) + | case MyNone + | + |val alpha = MyOption.<>(1) + |""".stripMargin + ) + + @Test def `enum-cases2` = + check( + """|enum MyOption: + | case <>[U](value: U) + | case MyNone + | + |val alpha = MyOption.<>(1) + |""".stripMargin, + )