Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a321575

Browse files
committedFeb 20, 2025·
Merge branch 'master' of https://github.com/vyperlang/vyper into fix/address_members_as_struct
2 parents 79ce92e + cd31867 commit a321575

File tree

5 files changed

+26
-17
lines changed

5 files changed

+26
-17
lines changed
 

‎tests/functional/codegen/features/iteration/test_for_in_list.py

+15
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,21 @@ def data() -> int128:
214214
assert c.data() == sum(xs)
215215

216216

217+
def test_constant_list_iter(get_contract):
218+
code = """
219+
MY_LIST: constant(uint24[4]) = [1, 2, 3, 4]
220+
221+
@external
222+
def foo() -> uint24:
223+
x: uint24 = 0
224+
for s: uint24 in MY_LIST:
225+
x += s
226+
return x
227+
"""
228+
c = get_contract(code)
229+
assert c.foo() == sum([1, 2, 3, 4])
230+
231+
217232
def test_basic_for_list_storage_address(get_contract):
218233
code = """
219234
addresses: address[3]

‎vyper/builtins/functions.py

+3-10
Original file line numberDiff line numberDiff line change
@@ -2293,19 +2293,12 @@ def build_IR(self, expr, args, kwargs, context):
22932293

22942294
else:
22952295
method_id = method_id_int("log(string,bytes)")
2296-
schema = args_abi_t.selector_name().encode("utf-8")
2297-
if len(schema) > 32:
2298-
raise CompilerPanic(f"print signature too long: {schema}")
22992296

2297+
schema = args_abi_t.selector_name().encode("utf-8")
23002298
schema_t = StringT(len(schema))
2301-
schema_buf = context.new_internal_variable(schema_t)
2302-
ret = ["seq"]
2303-
ret.append(["mstore", schema_buf, len(schema)])
2299+
schema_buf = Expr._make_bytelike(context, StringT, schema)
23042300

2305-
# TODO use Expr.make_bytelike, or better have a `bytestring` IRnode type
2306-
ret.append(
2307-
["mstore", add_ofst(schema_buf, 32), bytes_to_int(schema.ljust(32, b"\x00"))]
2308-
)
2301+
ret = ["seq"]
23092302

23102303
payload_buflen = args_abi_t.size_bound()
23112304
payload_t = BytesT(payload_buflen)

‎vyper/codegen/core.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ def _get_element_ptr_array(parent, key, array_bounds_check):
560560
return IRnode.from_list("~empty", subtype)
561561

562562
if parent.value == "multi":
563-
assert isinstance(key.value, int)
563+
assert isinstance(key.value, int), key
564564
return parent.args[key.value]
565565

566566
ix = unwrap_location(key)

‎vyper/codegen/expr.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -130,21 +130,22 @@ def parse_Hex(self):
130130
# String literals
131131
def parse_Str(self):
132132
bytez = self.expr.value.encode("utf-8")
133-
return self._make_bytelike(StringT, bytez)
133+
return self._make_bytelike(self.context, StringT, bytez)
134134

135135
# Byte literals
136136
def parse_Bytes(self):
137-
return self._make_bytelike(BytesT, self.expr.value)
137+
return self._make_bytelike(self.context, BytesT, self.expr.value)
138138

139139
def parse_HexBytes(self):
140140
# HexBytes already has value as bytes
141141
assert isinstance(self.expr.value, bytes)
142-
return self._make_bytelike(BytesT, self.expr.value)
142+
return self._make_bytelike(self.context, BytesT, self.expr.value)
143143

144-
def _make_bytelike(self, typeclass, bytez):
144+
@classmethod
145+
def _make_bytelike(cls, context, typeclass, bytez):
145146
bytez_length = len(bytez)
146147
btype = typeclass(bytez_length)
147-
placeholder = self.context.new_internal_variable(btype)
148+
placeholder = context.new_internal_variable(btype)
148149
seq = []
149150
seq.append(["mstore", placeholder, bytez_length])
150151
for i in range(0, len(bytez), 32):

‎vyper/codegen/stmt.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ def _parse_For_list(self):
258258
ret = ["seq"]
259259

260260
# list literal, force it to memory first
261-
if isinstance(self.stmt.iter, vy_ast.List):
261+
if iter_list.is_literal:
262262
tmp_list = self.context.new_internal_variable(iter_list.typ)
263263
ret.append(make_setter(tmp_list, iter_list))
264264
iter_list = tmp_list

0 commit comments

Comments
 (0)
Please sign in to comment.