-
-
Notifications
You must be signed in to change notification settings - Fork 804
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 all 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 |
---|---|---|
|
@@ -334,6 +334,11 @@ def __init__(self, typedef): | |
def __repr__(self): | ||
return f"type({self.typedef})" | ||
|
||
def check_modifiability_for_call(self, node, modifiability): | ||
if hasattr(self.typedef, "_ctor_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. ditto here -- all these if self._is_callable:
self.typedef._ctor_modifiability_for_call(...) |
||
return self.typedef._ctor_modifiability_for_call(node, modifiability) | ||
raise StructureException("Value is not callable", node) | ||
|
||
# dispatch into ctor if it's called | ||
def fetch_call_return(self, node): | ||
if hasattr(self.typedef, "_ctor_call_return"): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,8 +10,12 @@ | |
StructureException, | ||
UnfoldableNode, | ||
) | ||
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 | ||
|
@@ -81,6 +85,9 @@ | |
def _ctor_kwarg_types(self, node): | ||
return {} | ||
|
||
def _ctor_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 |
---|---|---|
|
@@ -14,8 +14,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 | ||
|
@@ -419,3 +420,6 @@ | |
) | ||
|
||
return self | ||
|
||
def _ctor_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.
as a general comment, i'd like to move these hasattr checks to be more like
that way we impose more structure on the APIs of callable types. but i think that can be pushed to "future work"