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

Error messages shows desugared code #42

Closed
EliasC opened this issue Dec 8, 2014 · 2 comments
Closed

Error messages shows desugared code #42

EliasC opened this issue Dec 8, 2014 · 2 comments
Assignees

Comments

@EliasC
Copy link
Contributor

EliasC commented Dec 8, 2014

The typechecker uses pretty printing to show the expression where an error has occured. This means that desugared expressions are shown in the error. For example, if the class Foo does not have a constructor, trying to typecheck the expression let x = new Foo(42) in x gives the error

No method '_init' in class 'Foo'
In expression: 
  __tmp__._init(42)
In expression: 
  {__tmp__._init(42);
   __tmp__}
In expression: 
  let __tmp__ = new Foo
  in
    {__tmp__._init(42);
     __tmp__}
...

I see two possible solutions:

  • Stop printing the exact expressions and instead print the corresponding line(s) from the original source code, possibly with the erroneous expression highlighted somehow:
No constructor in class 'Foo':
  let x = new Foo(42) in x
          ^^^^^^^^^^^
  • Store the sugared expressions in the desugared AST-nodes and pretty print those instead when there is an error.
No constructor in class 'Foo':
In expression:
  new Foo(42)
In expression:
  let x = new Foo(42) in x

Any thoughts or preferences?

@TobiasWrigstad
Copy link
Contributor

+1 vote for the 2nd option.

@EliasC
Copy link
Contributor Author

EliasC commented Dec 9, 2014

Second option implemented as of f26897b. The (strict) subexpressions of a desugared expression will not have a sugared representation, and will therefore not be printed in the backtrace.

Typechecking let x = new Foo(42) in x when there is no constructor in Foo gives the following error message:

No constructor in class 'Foo'
In expression: 
  new Foo(42)
In expression: 
  let x = new Foo(42)
  in
    x

There are some minor quirks; for example typechecking unless 42 then () gives the error

Operator 'not' is only defined for boolean types
In expression: 
  unless 42 then
    ()

but I think it works for now!

@EliasC EliasC closed this as completed Dec 9, 2014
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

No branches or pull requests

2 participants