|
16 | 16 | from src.ast import NodeVisitor |
17 | 17 | from src.api import errmsg |
18 | 18 |
|
19 | | -from src.api.constants import TYPE, SCOPE, CLASS |
| 19 | +from src.api.constants import TYPE, SCOPE, CLASS, KIND |
20 | 20 | from src.api.debug import __DEBUG__ |
21 | 21 | from src.api.errmsg import warning_not_used |
22 | 22 |
|
@@ -157,12 +157,15 @@ def visit_FUNCTION(self, node): |
157 | 157 | yield node |
158 | 158 | else: |
159 | 159 | 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'): |
161 | 162 | # String functions must *ALWAYS* return a value. |
162 | 163 | # Put a sentinel ("dummy") return "" sentence that will be removed if other is detected |
163 | 164 | lineno = node.lineno if not node.body else node.body[-1].lineno |
164 | 165 | 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)) |
166 | 169 | yield (yield self.generic_visit(node)) |
167 | 170 |
|
168 | 171 | def visit_LET(self, node): |
|
0 commit comments