Skip to content

Adjust error on bad enum #23080

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

som-snytt
Copy link
Contributor

Fixes #22734

First cut is in refchecks, second cut is in checking.

Not sure if checking will induce cycles.

I have an old branch to improve "missing members" in refchecks, but too much work to leverage here.

This message may make more sense in checking, where it is enum-specific. The user must fix the enum and not the case (perhaps).

@som-snytt som-snytt force-pushed the issue/22734-enum-missing-member branch from 6394792 to 9b3d4a1 Compare April 30, 2025 21:03
@som-snytt
Copy link
Contributor Author

Not a cycle but maybe opaque means abstract. Anyway it should only check abstract term.

The other caution is that it's easier to let refchecks do the work. What enum syntax is legal? Every tweak to the test is an indentation problem. So it's easier to have confidence in the refcheck in the first commit, because the def $new signals that the anon class must be concrete.

-- Error: tests/run/option-extract.scala:2:5 ---------------------------------------------------------------------------
 2 |enum Option[+A]:
   |^
   |enum class Option has an abstract member and an unparameterized case
 3 |  case Some(x: A)
 4 |  case None
 5 |  opaque type ExtractResult[B] = (=> B) => B
 6 |  def extract[B](f: A => B): ExtractResult[B] =
 7 |    def result(default: => B): B = (this: Option[A]) match
 8 |      case None => default
 9 |      case Some(elem) => f(elem)
10 |    result
11 |  extension [B](er: ExtractResult[B])
12 |    def orElse(default: => B): B = er(default)
13 |end Option

s"""|
|No errors expected/defined in $testSource -- use // error or // nopos-error"
|$showErrors
|""".stripMargin.trim.linesIterator.mkString("\n", "\n", "")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the most important part of this PR.

@som-snytt som-snytt marked this pull request as ready for review April 30, 2025 23:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect position on "object creation impossible" error in enums
1 participant