-
-
Notifications
You must be signed in to change notification settings - Fork 805
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
feat: allow constant interfaces #3718
Changes from 6 commits
3ed97ea
80eacfd
22c89a9
6e1106d
627b4f7
5910a5d
116bb7d
8f4b308
e7b029b
0c0f4ae
4924a85
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -645,11 +645,16 @@ def check_modifiability(node: vy_ast.VyperNode, modifiability: Modifiability) -> | |
return all(check_modifiability(item, modifiability) for item in node.elements) | ||
|
||
if isinstance(node, vy_ast.Call): | ||
args = node.args | ||
if len(args) == 1 and isinstance(args[0], vy_ast.Dict): | ||
return all(check_modifiability(v, modifiability) for v in args[0].values) | ||
|
||
call_type = get_exact_type_from_node(node.func) | ||
|
||
# structs and interfaces | ||
if isinstance(call_type, TYPE_T): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's more complicated but i think this actually should use |
||
call_type = call_type.typedef | ||
|
||
if hasattr(call_type, "check_modifiability_for_call"): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as a general comment, i'd like to move these hasattr checks to be more like if call_type._is_callable:
call_type.check_modifiability_for_call(...) that way we impose more structure on the APIs of callable types. but i think that can be pushed to "future work" |
||
return call_type.check_modifiability_for_call(node, modifiability) | ||
|
||
# builtins | ||
call_type_modifiability = getattr(call_type, "_modifiability", Modifiability.MODIFIABLE) | ||
return call_type_modifiability >= modifiability | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,12 @@ | |
from vyper.abi_types import ABI_Address, ABIType | ||
from vyper.ast.validation import validate_call_args | ||
from vyper.exceptions import InterfaceViolation, NamespaceCollision, StructureException | ||
from vyper.semantics.analysis.base import VarInfo | ||
from vyper.semantics.analysis.utils import validate_expected_type, validate_unique_method_ids | ||
from vyper.semantics.analysis.base import Modifiability, VarInfo | ||
from vyper.semantics.analysis.utils import ( | ||
check_modifiability, | ||
validate_expected_type, | ||
validate_unique_method_ids, | ||
) | ||
Comment on lines
+14
to
+18
Check notice Code scanning / CodeQL Cyclic import Note
Import of module
vyper.semantics.analysis.utils Error loading related location Loading |
||
from vyper.semantics.namespace import get_namespace | ||
from vyper.semantics.types.base import TYPE_T, VyperType | ||
from vyper.semantics.types.function import ContractFunctionT | ||
|
@@ -66,6 +70,9 @@ | |
def _ctor_kwarg_types(self, node): | ||
return {} | ||
|
||
def check_modifiability_for_call(self, node: vy_ast.Call, modifiability: Modifiability) -> bool: | ||
return check_modifiability(node.args[0], modifiability) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this will panic if |
||
|
||
# TODO x.validate_implements(other) | ||
def validate_implements(self, node: vy_ast.ImplementsDecl) -> None: | ||
namespace = get_namespace() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,8 +13,9 @@ | |
UnknownAttribute, | ||
VariableDeclarationException, | ||
) | ||
from vyper.semantics.analysis.base import Modifiability | ||
from vyper.semantics.analysis.levenshtein_utils import get_levenshtein_error_suggestions | ||
from vyper.semantics.analysis.utils import validate_expected_type | ||
from vyper.semantics.analysis.utils import check_modifiability, validate_expected_type | ||
Check notice Code scanning / CodeQL Cyclic import Note
Import of module
vyper.semantics.analysis.utils Error loading related location Loading |
||
from vyper.semantics.data_locations import DataLocation | ||
from vyper.semantics.types.base import VyperType | ||
from vyper.semantics.types.subscriptable import HashMapT | ||
|
@@ -408,3 +409,6 @@ | |
) | ||
|
||
return self | ||
|
||
def check_modifiability_for_call(self, node: vy_ast.Call, modifiability: Modifiability) -> bool: | ||
return all(check_modifiability(v, modifiability) for v in node.args[0].values) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same -- will panic if |
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 would be good for the tests if
bar()
andfaz()
returned something differentThere 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.
do you mean like any constant interface?
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.
yea, like 0xaaaa vs 0xbbbbb