Fix spurious unreachable and disallow-any errors from deferred passes #13575
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.
This diff:
Never
incorrectly marked as unreachable when function that's defined later with multiple argument decorator is called #13043except
containsAny
when inside a function that references a variable that is defined after the function and has an inferred type #13167For more concise repros of these various issues, see the modified test files. But in short, there were two broad categories of errors:
Within the deferred pass, we tend to infer 'Any' for the types of different variables instead of the actual type. This interacts badly with our unreachable and disallow-any checks and causes spurious errors.
Arguably, the better way of handling this error is to only collect errors during the final pass. I briefly experimented with this
approach, but was unable to find a clean, efficient, and non-disruptive way of implementing this. So, I settled for sprinkling in a few more
not self.current_node_deferred
checks.The
self.msg.disallowed_any_type(...)
call is normally guarded behind anot self.chk.current_node_deferred
check. However, we were bypassing this check forexcept
block assignments because we were deliberately setting that flag to False to work around some bug. For more context, see [WIP] Fix bug with exception variable reuse in deferred node. #2290.It appears we no longer need this patch anymore. I'm not entirely sure why, but I'm guessing we tightened and fixed the underlying problem with deferred passes some time during the past half-decade.