You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Improve error message for undefined user type #1993
semantic error: The type `ReRange` is not declared
or
semantic error: Unknown type `ReRange`
I think I like the second more.
Regarding "Unsupported type annotation: ReRange", that should be emitted for things like from typing import List. If you just do List[i32] without importing it from anywhere, then I think it should just say Unknown type List, and we can provide a "hint: did you mean list?"
(lp) ubaid@ubaids-MacBook-Pro lpython % cat examples/expr2.py
def main0():
x: ReRange
main0()
(lp) ubaid@ubaids-MacBook-Pro lpython % lpython examples/expr2.py
semantic error: Unknown type`ReRange`
--> examples/expr2.py:2:8
|
2 | x: ReRange
| ^^^^^^^
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 must be fixed).
(lp) ubaid@ubaids-MacBook-Pro lpython % cat examples/expr2.py
def main0():
x: ReRange[i32]
main0()
(lp) ubaid@ubaids-MacBook-Pro lpython % lpython examples/expr2.py
semantic error: Unknown type`ReRange`
--> examples/expr2.py:2:8
|
2 | x: ReRange[i32]
| ^^^^^^^^^^^^
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 must be fixed).
(lp) ubaid@ubaids-MacBook-Pro lpython % cat examples/expr2.py
def main0():
x: list[ReRange]
main0()
(lp) ubaid@ubaids-MacBook-Pro lpython % lpython examples/expr2.py
semantic error: Unknown type`ReRange`
--> examples/expr2.py:2:13
|
2 | x: list[ReRange]
| ^^^^^^^
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 must be fixed).
(lp) ubaid@ubaids-MacBook-Pro lpython % cat examples/expr2.py
def main0():
x: List[ReRange]
main0()
(lp) ubaid@ubaids-MacBook-Pro lpython % lpython examples/expr2.py
semantic error: Unknown type`List`
--> examples/expr2.py:2:8
|
2 | x: List[ReRange]
| ^^^^^^^^^^^^^
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 must be fixed).
If you just do List[i32] without importing it from anywhere, then I think it should just say Unknown type List, and we can provide a "hint: did you mean list?"
Is this a part of this issue? It seems there could several similar hints, for example Unknown type I32, hint: Use i32 and similarly for other types.
Now when I see the examples, "semantic error: Unknown type ReRange" seems a bit short --- it doesn't provide hints what should be done. Maybe "semantic error: The type ReRange is undeclared", suggesting that it should be declared first.
@rebcabin what exact error message text would you recommend here?
I like "semantic error: The type 'ReRange' is undeclared."
Note the punctuation: ReRange must appear in quotes and the entire message must end with a period because the message is a sentence with a subject, object, and verb. An error message like "Unknown type: ReRange" is also acceptable. In such an error message, ReRange is NOT in quotes and the message is not terminated with a period because the message is NOT a sentence, it's just a noun phrase. See any edition of "The Gregg Reference Manual" for the rules of English punctuation. It's important for our messages to be grammatical and correctly punctuated. Otherwise, fluent readers of English will be distracted by the errors in grammar or punctuation and readers will also get an impression that our outputs are less than professional.
I agree that grammatically incorrect error messages can be distracting. After changing the thrown error to 'semantic error: The type 'ReRange' is undeclared.' should the tests be updated?
Activity
ubaidsk commentedon Jun 22, 2023
With respect to this issue, shall we update the error message as follows:
diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp index b5b4ed779..401eb8b4c 100644 --- a/src/lpython/semantics/python_ast_to_asr.cpp +++ b/src/lpython/semantics/python_ast_to_asr.cpp @@ -1092,7 +1092,7 @@ public: } if( !type && raise_error ) { - throw SemanticError("Unsupported type annotation: " + var_annotation, loc); + throw SemanticError("Unknown type `" + var_annotation + "`", loc); } return type; (END)Some examples of how it would look:
ubaidsk commentedon Jun 22, 2023
Is this a part of this issue? It seems there could several similar hints, for example
Unknown type I32,hint: Use i32and similarly for other types.certik commentedon Jun 22, 2023
Yes, we can do hints in some other issue.
Now when I see the examples, "semantic error: Unknown type
ReRange" seems a bit short --- it doesn't provide hints what should be done. Maybe "semantic error: The typeReRangeis undeclared", suggesting that it should be declared first.@rebcabin what exact error message text would you recommend here?
tanay-man commentedon Feb 7, 2024
@certik Is this error message acceptable?
rebcabin commentedon Feb 7, 2024
I like "semantic error: The type 'ReRange' is undeclared."
Note the punctuation: ReRange must appear in quotes and the entire message must end with a period because the message is a sentence with a subject, object, and verb. An error message like "Unknown type: ReRange" is also acceptable. In such an error message, ReRange is NOT in quotes and the message is not terminated with a period because the message is NOT a sentence, it's just a noun phrase. See any edition of "The Gregg Reference Manual" for the rules of English punctuation. It's important for our messages to be grammatical and correctly punctuated. Otherwise, fluent readers of English will be distracted by the errors in grammar or punctuation and readers will also get an impression that our outputs are less than professional.
tanay-man commentedon Feb 7, 2024
I agree that grammatically incorrect error messages can be distracting. After changing the thrown error to 'semantic error: The type 'ReRange' is undeclared.' should the tests be updated?
rebcabin commentedon Feb 7, 2024
Yes, all the tests must pass before submitting a pull request :) We have continuous integration, too, which probably checks this.
Fixed issue lcompilers#1993 to improve readability of semantic error …
Merge pull request #2507 from tanay-man/main
Fixed issue lcompilers#1993 to improve readability of semantic error …
aryangupta701 commentedon Mar 24, 2024
is this solved?
ubaidsk commentedon Mar 24, 2024
With the latest main, the example in the issue description now gives:
ubaidsk commentedon Mar 24, 2024
I think this issue is fixed with the latest main.