fix[ux]: typechecking for loop annotation of list variable#4550
fix[ux]: typechecking for loop annotation of list variable#4550charles-cooper merged 5 commits intovyperlang:masterfrom
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #4550 +/- ##
==========================================
+ Coverage 92.35% 92.57% +0.22%
==========================================
Files 123 123
Lines 17543 17471 -72
Branches 2961 2951 -10
==========================================
- Hits 16201 16173 -28
+ Misses 938 894 -44
Partials 404 404 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
vyper/semantics/analysis/local.py
Outdated
| if not isinstance(iter_type, (DArrayT, SArrayT)): | ||
| raise InvalidType("Not an iterable type", iter_node) | ||
|
|
||
| if not target_type.compare_type(iter_type.value_type): |
There was a problem hiding this comment.
what happens if we don't move this into the try/except block?
There was a problem hiding this comment.
it would still work, just that it is a redundant check in the case of a literal list - but I think this is acceptable because your suggestion makes the code more readable.
charles-cooper
left a comment
There was a problem hiding this comment.
looks reasonable. @cyberthirst please take a look
|
possibly another for related bug: |
|
maybe we could improve the suggestion here? |
|
this fails on an assertion error: |
|
@cyberthirst these seem out of scope, right? like they were pre-existing errors prior to this PR? |
yeah, I think we should lift those to a separate issue/PR |
vyper/semantics/analysis/local.py
Outdated
|
|
||
| if not target_type.compare_type(iter_type.value_type): | ||
| raise TypeMismatch( | ||
| f"Iterator has a type of {target_type} but iterable has a type of {iter_type}", |
There was a problem hiding this comment.
maybe it would be better to refer to the value type inside the iterable?
There was a problem hiding this comment.
also, I think it would be better to point to the iterator instead of the iterable
because most likely the iterable is the correct thing, but the iterator is incorrectly annotated
so like - "TypeMismatch(Expected type of {iter_type.value_type}..." and then instead of using iter_node use the iterator node?
There was a problem hiding this comment.
Done! I had to pass target_node to _analyse_list_iter in order to raise the iterator node in the exception, which makes the function signature for _analyse_list_iter different from _analyse_range_iter (shouldn't be an issue?).
|
this should also close #3988 which should be the original issue where this bug was described |
opened a new issue: #4557 |
opened a new issue: #4558 |
opened a new issue: #4559 |
What I did
Fix #4549
How I did it
Add a check that the type derived for a variable list matches the iterator type specified in the for loop annotation.
How to verify it
See new tests.
Commit message
Description for the changelog
Typechecking for loop annotation of variable list
Cute Animal Picture