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

Nicer error messages on a likely forgotten resume #680

Open
jiribenes opened this issue Nov 8, 2024 · 1 comment
Open

Nicer error messages on a likely forgotten resume #680

jiribenes opened this issue Nov 8, 2024 · 1 comment
Labels
errormessage feature New feature or request

Comments

@jiribenes
Copy link
Contributor

Students (and many other users like me) often forget to resume from a handler.
We could customise the error message, especially when it's obvious from the type that using resume would fix the type error one gets.

Let's take a look at a small example:

effect get(): Int

def foo() = 
  try { println(do get()) }
  with get {
    42
//  ^^
//  Expected Unit but got Int.
  }

We could customise ( 🚲🏠 ) the error to something slightly more specific like:

Expected Unit but got Int.
Did you mean to use `resume: Int => Unit` in the handler in order to resume?

The heuristic is pretty straightforward: an additional hint should fire if in the handler we get "expected τ1 but got τ2" and resume has type τ2 => τ1.

@jiribenes jiribenes added feature New feature or request errormessage labels Nov 8, 2024
@jiribenes
Copy link
Contributor Author

If I'm looking at it correctly, the error message is produced by the body checkAgainst ret here (and we could use the resumeType):

// (4) synthesize type of continuation
val resumeType = if (isBidirectional) {
// resume { {f} => e }
val resumeType = FunctionType(Nil, cparams, Nil, bps, tpe, effs)
val resumeCapt = CaptureParam(Name.local("resumeBlock"))
FunctionType(Nil, List(resumeCapt), Nil, List(resumeType), ret, Effects.Pure)
} else {
// resume(v)
FunctionType(Nil, Nil, List(tpe), Nil, ret, Effects.Pure)
}
Context.bind(Context.symbolOf(resume).asBlockSymbol, resumeType, continuationCapt)
body checkAgainst ret

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
errormessage feature New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant