-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New semantic analyzer: fix recursive type aliases #7091
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
Conversation
This fixes maximum iteration count errors. Recursive type aliases still don't work and the behavior is a regression from the old semantic analyzer. Previously they were truncated, but now they aren't supported at all. We could perhaps hack something similar to what we used to have, but I don't think that it's urgent. This also breaks some use cases where "semi-recursive" type aliases were supported previously. The support mechanism caused infinite expansion for actual recursive type aliases. I couldn't come up with a simple way to support both, so I decided to prioritize fixing infinite expansion, as they have a worse impact on user experience. Work towards #6445.
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.
OK, the regression is a bit sad, but I can live with this.
@@ -2347,7 +2347,7 @@ def check_and_set_up_type_alias(self, s: AssignmentStmt) -> bool: | |||
self.analyze_alias(rvalue, allow_placeholder=True) | |||
if not res: | |||
return False | |||
if self.found_incomplete_ref(tag) or isinstance(res, PlaceholderType): | |||
if self.found_incomplete_ref(tag) or has_placeholder(res): |
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.
Please add a comment that we should only prohibit top-level placeholders as in base classes and NewTypes in long term, and this is a temporary measure.
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.
Added a comment.
main:4: error: Cannot resolve name "B" (possible cyclic definition) | ||
main:4: error: Cannot resolve name "C" (possible cyclic definition) | ||
main:7: note: Revealed type is 'Any' | ||
main:8: note: Revealed type is 'Any' |
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.
It looks like all new failures in this file are because of the problem with nested placeholders. Please add a comment in the existing issue mentioning this, and add links to the issue in these tests.
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.
Added new issues about this: #7111
This fixes maximum iteration count errors.
Recursive type aliases still don't work and the behavior is a
regression from the old semantic analyzer. Previously they were
truncated, but now they aren't supported at all. We could perhaps hack
something similar to what we used to have, but I don't think that it's
urgent.
This also breaks some use cases where "semi-recursive" type aliases
were supported previously. The support mechanism caused infinite
expansion for actual recursive type aliases. I couldn't come up with a
simple way to support both, so I decided to prioritize fixing infinite
expansion, as they have a worse impact on user experience.
Work towards #6445.