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

Unhelpful error message when effect keyword is misused as an interface #658

Open
jiribenes opened this issue Oct 31, 2024 · 0 comments
Open

Comments

@jiribenes
Copy link
Contributor

jiribenes commented Oct 31, 2024

The original Effekt paper uses the effect keyword for both an "interface" and a singleton operation:

effect Lexer {
  def peek(): Option[Token]
  def next(): Token
}

effect Emit {
  def text(content: String): Unit
  def newline(): Unit
}

effect LayoutChoice {
  def fail[A](): A
  def choice(): Direction
}

effect Next(): String
effect Choice(): Boolean

However, when you read the paper and just want to try things out on the website, you get a bizarre parser error:
Screenshot 2024-10-31 at 10 57 23

I think it would be nice to special case this exact syntax in the parser to provide a much nicer error message: something that underlines the effect keyword, says "Did you mean interface? ...", and ideally provides a quick-fix that works both in VSCode and on the website.


Relevant code

// effect <NAME>[...](...): ...
def operationDef(): Def =
nonterminal:
`effect` ~> operation() match {
case op @ Operation(id, tps, vps, bps, ret) =>
// TODO is the `true` flag used at all anymore???
InterfaceDef(IdDef(id.name), tps, List(Operation(id, Nil, vps, bps, ret) withPositionOf op))
}
def operation(): Operation =
nonterminal:
idDef() ~ params() ~ returnAnnotation() match {
case id ~ (tps, vps, bps) ~ ret => Operation(id, tps, vps, bps, ret)
}
def interfaceDef(): InterfaceDef =
nonterminal:
InterfaceDef(`interface` ~> idDef(), maybeTypeParams(), `{` ~> manyWhile(`def` ~> operation(), `def`) <~ `}`)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant