Skip to content

Commit

Permalink
Merge branch 'master' into fix/syntax-exception-missing-filename
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper authored Dec 13, 2024
2 parents 531cdca + c4669d1 commit 8e87405
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 10 deletions.
14 changes: 14 additions & 0 deletions tests/functional/codegen/types/numbers/test_exponents.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,17 @@ def foo(b: int128) -> int128:
c.foo(max_power)
with tx_failed():
c.foo(max_power + 1)


valid_list = [
"""
@external
def foo() -> uint256:
return (10**18)**2
"""
]


@pytest.mark.parametrize("good_code", valid_list)
def test_exponent_success(good_code):
assert compile_code(good_code) is not None
40 changes: 38 additions & 2 deletions tests/unit/compiler/test_source_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,44 @@ def update_foo():
self.foo += 1
"""
error_map = compile_code(code, output_formats=["source_map"])["source_map"]["error_map"]
assert "safeadd" in list(error_map.values())
assert "fallback function" in list(error_map.values())
assert "safeadd" in error_map.values()
assert "fallback function" in error_map.values()


def test_error_map_with_user_error():
code = """
@external
def foo():
raise "some error"
"""
error_map = compile_code(code, output_formats=["source_map"])["source_map"]["error_map"]
assert "user revert with reason" in error_map.values()


def test_error_map_with_user_error2():
code = """
@external
def foo(i: uint256):
a: DynArray[uint256, 10] = [1]
a[i % 10] = 2
"""
error_map = compile_code(code, output_formats=["source_map"])["source_map"]["error_map"]
assert "safemod" in error_map.values()


def test_error_map_not_overriding_errors():
code = """
@external
def foo(i: uint256):
raise self.bar(5%i)
@pure
def bar(i: uint256) -> String[32]:
return "foo foo"
"""
error_map = compile_code(code, output_formats=["source_map"])["source_map"]["error_map"]
assert "user revert with reason" in error_map.values()
assert "safemod" in error_map.values()


def test_compress_source_map():
Expand Down
15 changes: 10 additions & 5 deletions vyper/codegen/ir_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,13 +378,18 @@ 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 that don't have error_msg set
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}")
self._set_error_msg(error_msg)

def _set_error_msg(self, error_msg: str) -> None:
if self.error_msg is not None:
return
self.error_msg = error_msg
for arg in self.args:
arg.set_error_msg(error_msg)
arg._set_error_msg(error_msg)

# get the unique symbols contained in this node, which provides
# sanity check invariants for the optimizer.
Expand Down Expand Up @@ -627,7 +632,7 @@ def from_list(
else:
return cls(
obj[0],
[cls.from_list(o, ast_source=ast_source) for o in obj[1:]],
[cls.from_list(o, ast_source=ast_source, error_msg=error_msg) for o in obj[1:]],
typ,
location=location,
annotation=annotation,
Expand Down
2 changes: 1 addition & 1 deletion vyper/semantics/analysis/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def _validate_op(node, types_list, validation_fn_name):
try:
_validate_fn(node)
ret.append(type_)
except InvalidOperation as e:
except (InvalidOperation, OverflowException) as e:
err_list.append(e)

if ret:
Expand Down
4 changes: 2 additions & 2 deletions vyper/semantics/types/primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,11 @@ def _get_lr():
if isinstance(left, vy_ast.Int):
if left.value >= 2**value_bits:
raise OverflowException(
"Base is too large, calculation will always overflow", left
f"Base is too large for {self}, calculation will always overflow", left
)
elif left.value < -(2**value_bits):
raise OverflowException(
"Base is too small, calculation will always underflow", left
f"Base is too small for {self}, calculation will always underflow", left
)
elif isinstance(right, vy_ast.Int):
if right.value < 0:
Expand Down

0 comments on commit 8e87405

Please sign in to comment.