Skip to content

Commit e0af2ab

Browse files
committed
osutils: make static macro support elseif
1 parent 29eb4c6 commit e0af2ab

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

base/osutils.jl

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,21 @@ such as a `ccall` to a non-existent function.
1313
"""
1414
macro static(ex)
1515
if isa(ex, Expr)
16-
if ex.head === :if || ex.head === :&& || ex.head === :||
16+
@label loop
17+
hd = ex.head
18+
if hd (:if, :elseif, :&&, :||)
1719
cond = eval(__module__, ex.args[1])
18-
if xor(cond, ex.head === :||)
20+
if xor(cond, hd === :||)
1921
return esc(ex.args[2])
2022
elseif length(ex.args) == 3
21-
return esc(ex.args[3])
22-
elseif ex.head === :if
23+
br = ex.args[3]
24+
if br isa Expr && br.head === :elseif
25+
ex = br
26+
@goto loop
27+
else
28+
return esc(ex.args[3])
29+
end
30+
elseif hd (:if, :elseif)
2331
return nothing
2432
else
2533
return cond

test/osutils.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ end
2929
@test (@static false && 1) === false
3030
@test (@static true || 1) === true
3131
@test (@static false || 1) === 1
32+
@test (@static if false 1 elseif true 2 end) === 2
33+
@test (@static if false 1 elseif false 2 end) === nothing
34+
@test (@static if false 1 elseif false 2 else 3 end) === 3
35+
@test (@static if false 1 elseif false 2 elseif true && false 3 else 4 end) === 4
36+
@test (@static if false 1 elseif false 2 elseif true && false 3 end) === nothing
3237
end
3338

3439
if Sys.iswindows()

0 commit comments

Comments
 (0)