-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Avoid redundant extra errors after "Need type annotation for variable" #6998
Labels
priority-0-high
semantic-analyzer
Problems that happen during semantic analysis
topic-type-variables
topic-usability
Comments
ilevkivskyi
added
topic-type-variables
priority-0-high
topic-usability
semantic-analyzer
Problems that happen during semantic analysis
labels
Jun 15, 2019
ilevkivskyi
added a commit
that referenced
this issue
Jun 27, 2019
Fixes #6998 This PR makes several related changes: * Reserve `Cannot determine type` error for cases where node deferral failed etc (for example with runtime recursive definitions); don't show it after failed (ambiguous) type inference. * Always set reasonable variable type after failed inference (like `List[Any]` for an empty list). * Always give `Need type annotation for variable` error, not just for instances and tuples (that was ad-hoc IMO) This may actually give some _new_ errors as compared to status quo, but as one can see from the diff, the result is negative in number of (redundant) errors. There are couple changes in tests that look unrelated, these are because `is_same_type(..., UnboundType())` returns `True` for everything, including `UninhabitedType`. I would say we should actually avoid leaking unbound types from semantic analysis and replace the, with `Any`, but this is a separate issue.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
priority-0-high
semantic-analyzer
Problems that happen during semantic analysis
topic-type-variables
topic-usability
Consider this (oversimplified) example:
The subsequent errors look redundant (and maybe even annoying). This is more important with the new semantic analyzer because the old one doesn't show the error if the problematic variable was defined at the function scope.
Potentially, we can replace
<nothing>
withAny
after we show the error. Also the code that detects failed inference can be improved. For example,is_valid_inferred_type()
should be replaced with a proper type visitor.The text was updated successfully, but these errors were encountered: