Skip to content

Commit 2a5a565

Browse files
committed
Fix negative numebrs
1 parent 13a6949 commit 2a5a565

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
Features:
66

77
* Type checking for ==
8+
* Fix negative numbers
89

910
0.2.22
1011

pseudo_python/ast_translator.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -837,12 +837,19 @@ def _translate_unaryop(self, operand, op, location):
837837
raise type_check_error('- expects Int or Float',
838838
location, self.lines[location[0]],
839839
wrong_type=value_node['pseudo_type'])
840-
return {
841-
'type': 'unary_op',
842-
'op': '-',
843-
'value': value_node,
844-
'pseudo_type': value_node['pseudo_type']
845-
}
840+
if value_node['type'] == 'int':
841+
return {
842+
'type': 'int',
843+
'value': -value_node['value'],
844+
'pseudo_type': 'Int'
845+
}
846+
else;
847+
return {
848+
'type': 'unary_op',
849+
'op': '-',
850+
'value': value_node,
851+
'pseudo_type': value_node['pseudo_type']
852+
}
846853
elif isinstance(op, ast.Not):
847854
value_node = self._testable(self._translate_node(value))
848855
if value_node['type'] == 'standard_method_call' and value_node['message'] == 'present?':

0 commit comments

Comments
 (0)