Skip to content

Commit 17fb5f1

Browse files
authored
[Fix] UnaryOp constructor call (#175)
1 parent 38be5da commit 17fb5f1

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/mccode_antlr/common/expression.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ def __post_init__(self):
500500

501501
def as_type(self, pdt):
502502
value = [x.as_type(pdt) for x in self.value]
503-
return UnaryOp(self.op, value)
503+
return UnaryOp(data_type=self.data_type, style=self.style, op=self.op, value=value)
504504

505505
def _str_repr_(self, vstr):
506506
c_style = self.style == OpStyle.C

tests/test_expression.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,15 @@ def test_UnaryOp(self):
267267
not_val.style = OpStyle.PYTHON
268268
self.assertEqual(str(not_val), 'not val')
269269

270+
def test_UnaryOp_as_type(self):
271+
uop = UnaryOp(DataType.undefined, OpStyle.C, '__not__', Value.id('val'))
272+
self.assertEqual(str(uop), '!val')
273+
iop = uop.as_type(DataType.int)
274+
self.assertEqual(str(iop), '!val')
275+
fop = uop.as_type(DataType.float)
276+
self.assertEqual(str(fop), '!val')
277+
278+
270279
def test_numeric_BinaryOp(self):
271280
f = [Value.float(x) for x in range(3)]
272281
i = [Value.float(x) for x in range(3)]

0 commit comments

Comments
 (0)