-
Notifications
You must be signed in to change notification settings - Fork 323
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
Better context info in Type_Error
raised from return type checks
#8566
Conversation
Example:
yields:
|
This is a simple approach to ensuring better error messages - when creating the type ascriptions that enforce the type checks, we add a 'comment' to it that will then drive the error message. I was thinking of implementing a slightly cleaner approach where instead of adding the comment to the IR, we could deduce this in an IR pass from context (detecting the type check at the return of a function), but this seemed like a much simpler solution. Still I can try to do the 'better' one if we think this is not good. Alternative solutionI think the toher solution may need then to actually change the overall appproach to type checks - remove the I think regardless of this PR, I will try to experiment a bit with the current approach and see if this approach works well with the next steps of most basic type inference/propagation/checking. If I see that actually there the 'Alternative Solution' would be more desirable anyway, that may mean we should take it and scratch this PR - that's why I separated it from the base PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Computing a "comment" automatically and attaching it to IR
is fine. There is #8419 to start an effort of checking what's the fastest thing for runtime-compiler
to do.
fail("Expecting an exception, not: " + res); | ||
} catch (PolyglotException e) { | ||
assertContains("expected `expression` to be Integer, but got Text", e.getMessage()); | ||
assertContains("expected `x` result to be Integer, but got Text", e.getMessage()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be expecting 'x' to return Integer, but got Text
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I think that form may be more readable, I will update it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This definitely feels like a better error message for an unexpected return type from a method. I have even a better suggestion, I think.
engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/resolve/TypeSignatures.scala
Show resolved
Hide resolved
@@ -872,7 +872,7 @@ public void returnTypeCheckOptInError() throws Exception { | |||
var res = plusChecked.execute("a", "b"); | |||
fail("Expecting an exception, not: " + res); | |||
} catch (PolyglotException e) { | |||
assertContains("expected `expression` to be Integer, but got Text", e.getMessage()); | |||
assertContains("expected `plusChecked` result to be Integer, but got Text", e.getMessage()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about the following error message:
expected the result of `plusChecked` method to be Integer, but got Text
Isn't that even better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure it sounds good to me, I will amend when I will get around to moving this PR forward, thanks for the suggestion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just think that maybe function
may be a more universal name here?
method
fits well for Type.foo
methods. But internal helper functions e.g.:
foo x =
go i = ...
go 0
are not really _method_s, are they?
So maybe
expected the result of `plusChecked` function to be Integer, but got Text
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know. I thought that everything function-like in Enso is just called method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did
expected the result of `plusChecked` to be Integer, but got Text
avoiding the method/function controversy.
IMO it is readable.
WIP: somehow they do not propagate
75cf612
to
a40cd56
Compare
should be ok as its only in the error path
Pull Request Description
Important Notes
Checklist
Please ensure that the following checklist has been satisfied before submitting the PR:
Scala,
Java,
and
Rust
style guides. In case you are using a language not listed above, follow the Rust style guide.
./run ide build
.