Skip to content
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

refactor: ExprVisitor type validation #3739

Merged
merged 23 commits into from
Feb 5, 2024

Conversation

tserg
Copy link
Collaborator

@tserg tserg commented Jan 19, 2024

What I did

Standardize local visitor to always call validate_expected_type in the generic visit(), instead of on an ad-hoc basis within the visit for each node.

How I did it

How to verify it

Commit message

this commit simplifies the `ExprVisitor` implementation by moving calls
to `validate_expected_type` into the generic `visit()` function, instead
of having ad-hoc calls to validate_expected_type in the specialized
visitor functions.

in doing so, some inconsistencies in the generic implementation were
found and fixed:
- fix validate_expected_type for tuples
- introduce a void type for dealing with function calls/statements which
  don't return anything.

Description for the changelog

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

@codecov-commenter
Copy link

codecov-commenter commented Jan 19, 2024

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (01ec9a1) 84.73% compared to head (6bc398f) 84.61%.

Files Patch % Lines
vyper/semantics/analysis/utils.py 90.47% 1 Missing and 1 partial ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3739      +/-   ##
==========================================
- Coverage   84.73%   84.61%   -0.12%     
==========================================
  Files          92       92              
  Lines       13125    13122       -3     
  Branches     2928     2933       +5     
==========================================
- Hits        11121    11103      -18     
- Misses       1541     1555      +14     
- Partials      463      464       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines 498 to 502
if (
not isinstance(typ, TYPE_T)
and not isinstance(node, (vy_ast.Index, vy_ast.Tuple)) # can be deferred
and not isinstance(node.get_ancestor(), (vy_ast.Expr, vy_ast.Log))
):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are the exceptions that we need to work around, or alternatively it can also be skipped by wrapping the type in a TYPE_T for Expr, Log and Index nodes.

@@ -690,7 +667,7 @@ def visit_Subscript(self, node: vy_ast.Subscript, typ: VyperType) -> None:
index_types = get_possible_types_from_node(node.slice.value)
index_type = index_types.pop()

self.visit(node.slice, index_type)
self.visit(node.slice, TYPE_T(index_type))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this probably should be reverted (since removal of the Index ast node)

vyper/semantics/analysis/utils.py Dismissed Show dismissed Hide dismissed
@charles-cooper charles-cooper marked this pull request as ready for review February 5, 2024 15:27
Copy link
Member

@charles-cooper charles-cooper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work, lgtm. thanks!

@charles-cooper charles-cooper changed the title refactor: validation of expected type in generic visit refactor: ExprVisitor type validation Feb 5, 2024
@charles-cooper charles-cooper enabled auto-merge (squash) February 5, 2024 15:36
we should update the InvalidType exception raised in
validate_expected_type to raise TypeMismatch instead, but it can be a
follow-up PR
@charles-cooper charles-cooper merged commit e20885e into vyperlang:master Feb 5, 2024
84 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants