Skip to content

Commit

Permalink
update validation for dynarray functions
Browse files Browse the repository at this point in the history
  • Loading branch information
tserg committed Feb 8, 2022
1 parent fcc6f5b commit a38902e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 6 additions & 2 deletions vyper/semantics/validation/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from vyper.exceptions import StructureException
from vyper.semantics.types import ArrayDefinition
from vyper.semantics.types.bases import BaseTypeDefinition
from vyper.semantics.types.indexable.sequence import DynamicArrayFunctionDefinition
from vyper.semantics.types.function import ContractFunction
from vyper.semantics.types.user.event import Event
from vyper.semantics.types.user.struct import StructPrimitive
Expand Down Expand Up @@ -125,9 +126,9 @@ def visit_BoolOp(self, node, type_):

def visit_Call(self, node, type_):
call_type = get_exact_type_from_node(node.func)
node._metadata["type"] = type_ or call_type.fetch_call_return(node)
node_type = type_ or call_type.fetch_call_return(node)
node._metadata["type"] = node_type
self.visit(node.func)

if isinstance(call_type, (Event, ContractFunction)):
# events and internal function calls
for arg, arg_type in zip(node.args, list(call_type.arguments.values())):
Expand All @@ -136,6 +137,9 @@ def visit_Call(self, node, type_):
# literal structs
for value, arg_type in zip(node.args[0].values, list(call_type.members.values())):
self.visit(value, arg_type)
elif isinstance(call_type, DynamicArrayFunctionDefinition):
for arg in node.args:
self.visit(arg, node_type.value_type)
elif node.func.id not in ("empty", "range"):
# builtin functions
for arg in node.args:
Expand Down
6 changes: 3 additions & 3 deletions vyper/semantics/validation/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from vyper.semantics.types.indexable.sequence import (
ArrayDefinition,
DynamicArrayDefinition,
DynamicArrayFunctionDefinition,
TupleDefinition,
)
from vyper.semantics.types.user.event import Event
Expand Down Expand Up @@ -444,7 +445,6 @@ def visit_For(self, node):
def visit_Expr(self, node):
if not isinstance(node.value, vy_ast.Call):
raise StructureException("Expressions without assignment are disallowed", node)

fn_type = get_exact_type_from_node(node.value.func)
if isinstance(fn_type, Event):
raise StructureException("To call an event you must use the `log` statement", node)
Expand All @@ -463,9 +463,9 @@ def visit_Expr(self, node):
raise StateAccessViolation(
f"Cannot call any function from a {self.func.mutability.value} function", node
)

return_value = fn_type.fetch_call_return(node.value)
if return_value and not isinstance(fn_type, ContractFunction):
if return_value and not isinstance(fn_type, DynamicArrayFunctionDefinition) and \
not isinstance(fn_type, ContractFunction):
raise StructureException(
f"Function '{fn_type._id}' cannot be called without assigning the result", node
)
Expand Down

0 comments on commit a38902e

Please sign in to comment.