Skip to content

Commit bc6a891

Browse files
committed
Fix not adding sentinel to subs
1 parent e1c0c12 commit bc6a891

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

src/api/optimize.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from src.ast import NodeVisitor
1717
from src.api import errmsg
1818

19-
from src.api.constants import TYPE, SCOPE, CLASS
19+
from src.api.constants import TYPE, SCOPE, CLASS, KIND
2020
from src.api.debug import __DEBUG__
2121
from src.api.errmsg import warning_not_used
2222

@@ -157,12 +157,15 @@ def visit_FUNCTION(self, node):
157157
yield node
158158
else:
159159
node.visited = True
160-
if node.body.token == 'BLOCK' and (not node.body or node.body[-1].token != 'RETURN'):
160+
if node.kind == KIND.function and node.body.token == 'BLOCK' and \
161+
(not node.body or node.body[-1].token != 'RETURN'):
161162
# String functions must *ALWAYS* return a value.
162163
# Put a sentinel ("dummy") return "" sentence that will be removed if other is detected
163164
lineno = node.lineno if not node.body else node.body[-1].lineno
164165
errmsg.warning_function_should_return_a_value(lineno, node.name, node.filename)
165-
node.body.append(symbols.ASM('\nld hl, 0\n', lineno, node.filename, is_sentinel=True))
166+
type_ = node.type_
167+
if type_ is not None and type_ == self.TYPE(TYPE.string):
168+
node.body.append(symbols.ASM('\nld hl, 0\n', lineno, node.filename, is_sentinel=True))
166169
yield (yield self.generic_visit(node))
167170

168171
def visit_LET(self, node):

0 commit comments

Comments
 (0)