Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unapply completions should be completed in nested unapply context #19972

Closed
rochala opened this issue Mar 18, 2024 · 0 comments · Fixed by #20274
Closed

Unapply completions should be completed in nested unapply context #19972

rochala opened this issue Mar 18, 2024 · 0 comments · Fixed by #20274
Assignees
Labels
area:presentation-compiler Related to the presentation compiler module used by Metals and possibly other tools itype:bug
Milestone

Comments

@rochala
Copy link
Contributor

rochala commented Mar 18, 2024

Compiler version

3.4.1

Minimized code

This test should be changed and pass.

  // file dotty/tools/pc/tests/completion/CompletionSuite.scala
  @Test def pat1 =
    check(
      s"""|object Main {
          |  Option(1) match {
          |    case List(Som@@)
          |}
          |""".stripMargin,
      """|Some(value) scala
         |Some scala
         |""".stripMargin
    )

Output

      """|Some scala
         |Some[A](value: A): Some[A]
         |""".stripMargin

Expectation

Extra unapply completion should be added to the completion list, where it is allowed and completion with expected type parameters should be filtered as it is illegal at this position.
The test should pass.

Tips

My guess is that the root of the issue is in CaseDefCompletions, which is responsible for providing us with extra results. The logic probably matches against specific patterns, but what we should do instead is to recursively try to find whether one of the owners is case definition and all other owners in between are unapply methods.

@rochala rochala added itype:bug area:presentation-compiler Related to the presentation compiler module used by Metals and possibly other tools labels Mar 18, 2024
natsukagami added a commit that referenced this issue May 22, 2024
Fixes #19972.

Add pattern completion for `Unapply` tree contexts.

A typical example would be
```scala
optionList match
    case List(S@@)
```
which should be prompted `Some(value)`, due to `List.unapplySeq`
expecting `Option[T]` patterns as arguments.
@Kordyjan Kordyjan added this to the 3.5.1 milestone Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:presentation-compiler Related to the presentation compiler module used by Metals and possibly other tools itype:bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants