Skip to content
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

fix[lang]: show user error in error map #4286

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions vyper/codegen/ir_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,7 @@ def is_complex_ir(self):
and self.value.lower() not in do_not_cache
)

# set an error message and push down into all children.
# useful for overriding an error message generated by a helper
# function with a more specific error message.
# set an error message and push down to its children.
def set_error_msg(self, error_msg: str) -> None:
if self.error_msg is not None:
raise CompilerPanic(f"{self.value} already has error message {self.error_msg}")
Expand Down Expand Up @@ -600,7 +598,7 @@ def from_list(
) -> "IRnode":
if isinstance(typ, str): # pragma: nocover
raise CompilerPanic(f"Expected type, not string: {typ}")

ret = None
if isinstance(obj, IRnode):
# note: this modify-and-returnclause is a little weird since
# the input gets modified. CC 20191121.
Expand All @@ -612,12 +610,10 @@ def from_list(
obj.location = location
if obj.encoding is None:
obj.encoding = encoding
if obj.error_msg is None:
obj.error_msg = error_msg

return obj
ret = obj
elif not isinstance(obj, list):
return cls(
ret = cls(
obj,
[],
typ,
Expand All @@ -627,12 +623,11 @@ def from_list(
add_gas_estimate=add_gas_estimate,
ast_source=ast_source,
encoding=encoding,
error_msg=error_msg,
is_self_call=is_self_call,
passthrough_metadata=passthrough_metadata,
)
else:
return cls(
ret = cls(
obj[0],
[cls.from_list(o, ast_source=ast_source) for o in obj[1:]],
typ,
Expand All @@ -642,7 +637,9 @@ def from_list(
ast_source=ast_source,
add_gas_estimate=add_gas_estimate,
encoding=encoding,
error_msg=error_msg,
is_self_call=is_self_call,
passthrough_metadata=passthrough_metadata,
)
if error_msg is not None:
ret.set_error_msg(error_msg)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe _set_error_msg, since the IRnode may already have error_msg set

return ret
4 changes: 1 addition & 3 deletions vyper/codegen/stmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,7 @@ def _assert_reason(self, test_expr, msg):
else:
ir_node = ["if", ["iszero", test_expr], revert_seq]

ir_node = IRnode.from_list(ir_node)
ir_node.set_error_msg("user revert with reason")
return ir_node
return IRnode.from_list(ir_node, error_msg="user revert with reason")

def parse_Assert(self):
test_expr = Expr.parse_value_expr(self.stmt.test, self.context)
Expand Down
Loading