Skip to content

Commit 91f4636

Browse files
authored
Merge pull request #840 from boriel-basic/fix/unrechable_code_warning_with_enable-break
fix: do not emit spurious warning with --enable-break
2 parents 35cab4e + ae7ebb6 commit 91f4636

4 files changed

Lines changed: 64 additions & 2 deletions

File tree

src/api/optimize.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def visit_FUNCTION(self, node: symbols.ID):
9191
if (
9292
node.class_ == CLASS.function
9393
and node.body.token == "BLOCK"
94-
and (not node.body or node.body[-1].token != "RETURN")
94+
and (not node.body or node.body[-1].token not in ("CHKBREAK", "RETURN"))
9595
):
9696
# String functions must *ALWAYS* return a value.
9797
# Put a sentinel ("dummy") return "" sentence that will be removed if other is detected
@@ -109,7 +109,7 @@ def visit_BLOCK(self, node):
109109
i = 0
110110
while i < len(node) - 1:
111111
child = node[i]
112-
if child.token == "LABEL" and node[i + 1].token == "CHKBREAK":
112+
if child.token in ("LABEL", "RETURN") and node[i + 1].token == "CHKBREAK":
113113
node.pop(i + 1)
114114
continue
115115
i += 1
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
org 32768
2+
.core.__START_PROGRAM:
3+
di
4+
push ix
5+
push iy
6+
exx
7+
push hl
8+
exx
9+
ld hl, 0
10+
add hl, sp
11+
ld (.core.__CALL_BACK__), hl
12+
ei
13+
jp .core.__MAIN_PROGRAM__
14+
.core.__CALL_BACK__:
15+
DEFW 0
16+
.core.ZXBASIC_USER_DATA:
17+
; Defines USER DATA Length in bytes
18+
.core.ZXBASIC_USER_DATA_LEN EQU .core.ZXBASIC_USER_DATA_END - .core.ZXBASIC_USER_DATA
19+
.core.__LABEL__.ZXBASIC_USER_DATA_LEN EQU .core.ZXBASIC_USER_DATA_LEN
20+
.core.__LABEL__.ZXBASIC_USER_DATA EQU .core.ZXBASIC_USER_DATA
21+
.core.ZXBASIC_USER_DATA_END:
22+
.core.__MAIN_PROGRAM__:
23+
call _distance
24+
ld (0), a
25+
ld hl, 0
26+
ld b, h
27+
ld c, l
28+
.core.__END_PROGRAM:
29+
di
30+
ld hl, (.core.__CALL_BACK__)
31+
ld sp, hl
32+
exx
33+
pop hl
34+
exx
35+
pop iy
36+
pop ix
37+
ei
38+
ret
39+
_distance:
40+
push ix
41+
ld ix, 0
42+
add ix, sp
43+
ld hl, 0
44+
push hl
45+
ld l, (ix-2)
46+
ld h, (ix-1)
47+
ld a, l
48+
_distance__leave:
49+
ld sp, ix
50+
pop ix
51+
ret
52+
;; --- end of user code ---
53+
END
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FUNCTION distance () as uByte
2+
DIM c as integer
3+
return CAST(uByte,c)
4+
END FUNCTION
5+
6+
POKE 0, distance()
7+

tests/functional/cmdline/test_warning.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ mcleod3.bas:3: error: 'GenerateSpaces' is neither an array nor a function.
88
>>> process_file('arch/zx48k/doloop2.bas', ['-S', '-q', '-O -W110'])
99
doloop2.bas:4: warning: [W100] Using default implicit type 'ubyte' for 'a'
1010
doloop2.bas:4: warning: [W150] Variable 'a' is never used
11+
12+
>>> process_file('arch/zx48k/warn_brk.bas', ['-S', '-q', '-O --enable-break'])

0 commit comments

Comments
 (0)