Skip to content

Commit fa71cc9

Browse files
authored
Merge branch 'vyperlang:master' into feat/send_gas_stipend
2 parents fc18409 + e60b021 commit fa71cc9

File tree

6 files changed

+71
-13
lines changed

6 files changed

+71
-13
lines changed

docs/built-in-functions.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ Utilities
891891

892892
.. note::
893893

894-
The EVM only provides access to the most recent 256 blocks. This function returns ``EMPTY_BYTES32`` if the block number is greater than or equal to the current block number or more than 256 blocks behind the current block.
894+
The EVM only provides access to the most recent 256 blocks. This function reverts if the block number is greater than or equal to the current block number or more than 256 blocks behind the current block.
895895

896896
.. code-block:: python
897897

tests/parser/exceptions/test_syntax_exception.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ def foo():
7474
"""
7575
a: internal(uint256)
7676
""",
77+
"""
78+
@external
79+
def foo():
80+
x: uint256 = +1 # test UAdd ast blocked
81+
""",
7782
]
7883

7984

tests/parser/features/iteration/test_break.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
from decimal import Decimal
22

3+
import pytest
4+
5+
from vyper.exceptions import StructureException
6+
37

48
def test_break_test(get_contract_with_gas_estimation):
59
break_test = """
@@ -79,3 +83,41 @@ def foo(n: int128) -> int128:
7983
assert c.foo(200) == 23
8084
assert c.foo(4000000) == 66
8185
print("Passed aug-assignment break composite test")
86+
87+
88+
fail_list = [
89+
(
90+
"""
91+
@external
92+
def foo():
93+
a: uint256 = 3
94+
break
95+
""",
96+
StructureException,
97+
),
98+
(
99+
"""
100+
@external
101+
def foo():
102+
if True:
103+
break
104+
""",
105+
StructureException,
106+
),
107+
(
108+
"""
109+
@external
110+
def foo():
111+
for i in [1, 2, 3]:
112+
b: uint256 = i
113+
if True:
114+
break
115+
""",
116+
StructureException,
117+
),
118+
]
119+
120+
121+
@pytest.mark.parametrize("bad_code,exc", fail_list)
122+
def test_block_fail(assert_compile_failed, get_contract_with_gas_estimation, bad_code, exc):
123+
assert_compile_failed(lambda: get_contract_with_gas_estimation(bad_code), exc)

tests/parser/features/iteration/test_continue.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import pytest
22

3+
from vyper.exceptions import StructureException
4+
35

46
def test_continue1(get_contract_with_gas_estimation):
57
code = """
@@ -59,29 +61,38 @@ def foo() -> int128:
5961

6062

6163
fail_list = [
62-
"""
64+
(
65+
"""
6366
@external
6467
def foo():
6568
a: uint256 = 3
6669
continue
6770
""",
68-
"""
71+
StructureException,
72+
),
73+
(
74+
"""
6975
@external
7076
def foo():
7177
if True:
7278
continue
7379
""",
74-
"""
80+
StructureException,
81+
),
82+
(
83+
"""
7584
@external
7685
def foo():
7786
for i in [1, 2, 3]:
7887
b: uint256 = i
7988
if True:
8089
continue
8190
""",
91+
StructureException,
92+
),
8293
]
8394

8495

85-
@pytest.mark.parametrize("bad_code", fail_list)
86-
def test_block_fail(assert_compile_failed, get_contract_with_gas_estimation, bad_code):
87-
assert_compile_failed(lambda: get_contract_with_gas_estimation(bad_code))
96+
@pytest.mark.parametrize("bad_code,exc", fail_list)
97+
def test_block_fail(assert_compile_failed, get_contract_with_gas_estimation, bad_code, exc):
98+
assert_compile_failed(lambda: get_contract_with_gas_estimation(bad_code), exc)

vyper/ast/annotation.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,6 @@ def visit_UnaryOp(self, node):
230230
"""
231231
self.generic_visit(node)
232232

233-
# TODO once grammar is updated, remove this
234-
# UAdd has no effect on the value of it's operand, so it is discarded
235-
if isinstance(node.op, python_ast.UAdd):
236-
return node.operand
237-
238233
is_sub = isinstance(node.op, python_ast.USub)
239234
is_num = (
240235
hasattr(node.operand, "n")

vyper/semantics/analysis/local.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def _validate_msg_data_attribute(node: vy_ast.Attribute) -> None:
160160

161161
class FunctionNodeVisitor(VyperNodeVisitorBase):
162162

163-
ignored_types = (vy_ast.Break, vy_ast.Constant, vy_ast.Pass)
163+
ignored_types = (vy_ast.Constant, vy_ast.Pass)
164164
scope_name = "function"
165165

166166
def __init__(
@@ -289,6 +289,11 @@ def visit_Continue(self, node):
289289
if for_node is None:
290290
raise StructureException("`continue` must be enclosed in a `for` loop", node)
291291

292+
def visit_Break(self, node):
293+
for_node = node.get_ancestor(vy_ast.For)
294+
if for_node is None:
295+
raise StructureException("`break` must be enclosed in a `for` loop", node)
296+
292297
def visit_Return(self, node):
293298
values = node.value
294299
if values is None:

0 commit comments

Comments
 (0)