Fix crashes on incorectly detected recursive aliases #18625
Merged
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.
Fixes #18505
Fixes #16757
Fixing the crash is trivial, we simply give an error on something like
type X = X
, instead of crashing. But then I looked at what people actually want to do, they want to create an alias to something currently in scope (not a meaningless no-op alias). Right now we special-case classes/aliases to allow forward references (including recursive type aliases). However, I don't think we have any clear "scoping rules" for forward references. For example:where
Y
should point to,__main__.X
or__main__.C.X
? Moreover, before this PR forward references can take precedence over real references:After some thinking I found this is not something I can fix in a simple PR. So instead I do just two things here: