effekt-lang / effekt

A language with lexical effect handlers and lightweight effect polymorphism
https://effekt-lang.org
MIT License
334 stars 24 forks source link

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

Open jiribenes opened 3 weeks ago

jiribenes commented 3 weeks ago

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

https://github.com/effekt-lang/effekt/blob/6e71bcd59bf419f2ba5923d9eca519b87d3804b5/effekt/shared/src/main/scala/effekt/RecursiveDescent.scala#L469-L486