Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions src/mccode_antlr/common/expression/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,11 +410,11 @@ def has_value(self) -> bool:

@property
def vector_known(self) -> bool:
return self.is_vector and len(self._exprs) > 1
return self.is_vector and (len(self._exprs) > 1 or self.object_type == ObjectType.initializer_list)

@property
def value(self):
if self.is_vector and not self.is_singular:
if self.vector_known:
# Return list of Python values for each element
result = []
for e in map(_char_codes, self._exprs):
Expand Down
7 changes: 7 additions & 0 deletions tests/test_c_initializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ def test_expr_parse_brace_list():
assert expr.value == [1.0, 2.0, 3.0, 4.0]


def test_expr_parse_single_element_brace_list():
"""``{80}`` is a one-element vector, not the scalar 80."""
expr = Expr.parse('{80}')
assert expr.vector_known
assert expr.value == [80]


@pytest.mark.parametrize('declaration, values', [
('double edges[4] = {1.0, 2.0, 3.0, 4.0};', [1.0, 2.0, 3.0, 4.0]),
('double edges[] = {1.0, 2.0};', [1.0, 2.0]),
Expand Down
Loading