Skip to content

Commit

Permalink
rm validate_expected_type from local
Browse files Browse the repository at this point in the history
  • Loading branch information
tserg committed Jul 25, 2023
1 parent 723fcba commit e2f8206
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions vyper/semantics/analysis/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,6 @@ def _check_iterator_modification(
return None


def _validate_revert_reason(msg_node: vy_ast.VyperNode) -> None:
if msg_node:
if isinstance(msg_node, vy_ast.Str):
if not msg_node.value.strip():
raise StructureException("Reason string cannot be empty", msg_node)
elif not (isinstance(msg_node, vy_ast.Name) and msg_node.id == "UNREACHABLE"):
try:
validate_expected_type(msg_node, StringT(1024))
except TypeMismatch as e:
raise InvalidType("revert reason must fit within String[1024]") from e


# helpers
def _validate_address_code(node: vy_ast.Attribute, value_type: VyperType) -> None:
if isinstance(value_type, AddressT) and node.attr == "code":
Expand Down Expand Up @@ -262,7 +250,6 @@ def visit_AnnAssign(self, node):
)

typ = type_from_annotation(node.annotation, DataLocation.MEMORY)
# validate_expected_type(node.value, typ)

try:
self.namespace[name] = VarInfo(typ, location=DataLocation.MEMORY)
Expand Down Expand Up @@ -298,7 +285,6 @@ def visit_Assign(self, node):
"Left-hand side of assignment cannot be a HashMap without a key", node
)

# validate_expected_type(node.value, target.typ)
target.validate_modification(node, self.func.mutability)

self.expr_visitor.visit(node.target, target.typ)
Expand All @@ -314,7 +300,6 @@ def visit_AugAssign(self, node):

lhs_info = get_expr_info(node.target)

# validate_expected_type(node.value, lhs_info.typ)
lhs_info.validate_modification(node, self.func.mutability)

self.expr_visitor.visit(node.value, lhs_info.typ)
Expand Down Expand Up @@ -562,8 +547,18 @@ def visit_Log(self, node):
self.expr_visitor.visit(node.value, f.typedef)

def visit_Raise(self, node):
if node.exc:
_validate_revert_reason(node.exc)
msg_node = node.exc
if msg_node:
if isinstance(msg_node, vy_ast.Str):
if not msg_node.value.strip():
raise StructureException("Reason string cannot be empty", msg_node)
elif not (isinstance(msg_node, vy_ast.Name) and msg_node.id == "UNREACHABLE"):
try:
self.expr_visitor.visit(msg_node, StringT(1024))
except TypeMismatch as e:
raise InvalidType("revert reason must fit within String[1024]") from e



def visit_Return(self, node):
values = node.value
Expand Down Expand Up @@ -926,9 +921,6 @@ def visit_Name(self, node: vy_ast.Name, typ: Optional[VyperType] = None) -> None
except VyperException as exc:
raise exc.with_annotation(node) from None

# if not isinstance(typ, TYPE_T):
# validate_expected_type(node, typ)

def visit_Subscript(self, node: vy_ast.Subscript, typ: Optional[VyperType] = None) -> None:
if isinstance(typ, TYPE_T):
# don't recurse; can't annotate AST children of type definition
Expand Down

0 comments on commit e2f8206

Please sign in to comment.