-
Notifications
You must be signed in to change notification settings - Fork 171
Make error messages consistent #678
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
Draft
faze-geek
wants to merge
1
commit into
lcompilers:main
Choose a base branch
from
faze-geek:correct_error
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| def main(): | ||
| s : str | ||
| c : c32 | ||
| c = 1+ 1j | ||
| s = "abc" + c | ||
| print(s) | ||
|
|
||
| main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| { | ||
| "basename": "asr-test_str_mismatch-4aad88f", | ||
| "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", | ||
| "infile": "tests/errors/test_str_mismatch.py", | ||
| "infile_hash": "cb0d79659e231dea35ff7fb9a0b3d61ea4e61a97a084dd4ef5897a74", | ||
| "outfile": null, | ||
| "outfile_hash": null, | ||
| "stdout": null, | ||
| "stdout_hash": null, | ||
| "stderr": "asr-test_str_mismatch-4aad88f.stderr", | ||
| "stderr_hash": "e64e38a8c35e63d2f542f67e1d133be318f46eac1f0e5aa1f187ca19", | ||
| "returncode": 2 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| semantic error: Type mismatch in binary operator; the types must be compatible | ||
| --> tests/errors/test_str_mismatch.py:5:9 | ||
| | | ||
| 5 | s = "abc" + c | ||
| | ^^^^^ ^ type mismatch (str and c32) | ||
|
Comment on lines
+1
to
+5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We get this message using the $ lpython examples/expr2.py
semantic error: Type mismatch in binary operator; the types must be compatible
--> examples/expr2.py:5:9
|
5 | s = "abc" + c
| ^^^^^ ^ type mismatch (str and c64)
Note: if any of the above error or warning messages are not clear or are lacking
context please report it to us (we consider that a bug that needs to be fixed).I think this is fixed. |
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 change makes LPython return the correct message.
One thing that worries me is that this branch of the if statement structure in this function does not do anything after this change. Is that a good design of
cast_helper?It seems that
cast_helpergives an error message right away if things cannot be cast. In which case, maybe we should just reformulate what this error message says. Instead of saying "not implemented", we should say "cannot cast c32 to string".I do like the current error message (in this PR, as seen in the tests). Do we effectively have two places in LPython that return the error? In
cast_helperand then later as well?Should we just have one place, say
cast_helper, that checks for errors, and then later we assume they are correct?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.
Well IMO,
cast_helperis not abstract enough. Instead of a longif-else-ifladder I would prefer a simple rule map based with a tuple of type as keys and the desired cast as the value. Just pass in the types to the rule map and get your cast type. But anyways doesn't matter much now as its already implemented so let's keep using it.Agreed. The second message is more transparent and helps in debugging.
In an abstract sense, yes there should be only one place which checks for type compatibilities and return errors. If no errors then assume correctness in rest of your implementation.
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.
@faze-geek Why have you removed this
SemanticErroranyways?Uh oh!
There was an error while loading. Please reload this page.
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.
The current
SemanticErroris inconsistent (as pointed in #673) so first I was changing the error inside theelseitself . But then by--show-stacktraceI realised that by removing these lines , thetype mismatcherrors for 1.str + int, 2.str + floatand 3.str + complexwere getting generated from the same lines in the code ( which I thought is better than error generated from different lines)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 thought this would be straightforward ,I was unaware of
cast_helper.