Skip to content

Commit eb2a09c

Browse files
committed
More tests, typo fix, delete an unused arg
1 parent 0c6ff8b commit eb2a09c

File tree

5 files changed

+84
-5
lines changed

5 files changed

+84
-5
lines changed

src/desugaring.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2112,7 +2112,7 @@ end
21122112

21132113
# Separate decls and assignments (which require re-expansion)
21142114
# local x, (y=2), z ==> local x; local z; y = 2
2115-
function expand_decls(ctx, ex, is_const=false)
2115+
function expand_decls(ctx, ex)
21162116
declkind = kind(ex)
21172117
@assert declkind in KSet"local global"
21182118
declmeta = get(ex, :meta, nothing)
@@ -2124,7 +2124,7 @@ function expand_decls(ctx, ex, is_const=false)
21242124
@chk numchildren(binding) == 2
21252125
lhs = strip_decls!(ctx, stmts, declkind, declmeta, binding[1])
21262126
push!(stmts, expand_assignment(ctx, @ast ctx binding [kb lhs binding[2]]))
2127-
elseif is_sym_decl(binding) && !is_const
2127+
elseif is_sym_decl(binding)
21282128
strip_decls!(ctx, stmts, declkind, declmeta, binding)
21292129
else
21302130
throw(LoweringError(ex, "invalid syntax in variable declaration"))
@@ -3085,7 +3085,7 @@ function expand_arrow_arglist(ctx, arglist, arrowname)
30853085
if k == K"where"
30863086
@ast ctx arglist [K"where"
30873087
expand_arrow_arglist(ctx, arglist[1], arrowname)
3088-
argslist[2]
3088+
arglist[2]
30893089
]
30903090
else
30913091
# The arglist can sometimes be parsed as a block, or something else, and
@@ -3098,7 +3098,6 @@ function expand_arrow_arglist(ctx, arglist, arrowname)
30983098
[K"parameters" arglist[2]]
30993099
]
31003100
elseif k != K"tuple"
3101-
# `x::Int -> body`
31023101
arglist = @ast ctx arglist [K"tuple"
31033102
arglist[1]
31043103
]

src/eval.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function add_ir_debug_info!(current_codelocs_stack, stmt)
8484
current_codelocs_stack[j][1] != locstk[j][1])
8585
while length(current_codelocs_stack) >= j
8686
info = pop!(current_codelocs_stack)
87-
!isempty(current_codelocs_stack) && push!(last(current_codelocs_stack)[2], info)
87+
push!(last(current_codelocs_stack)[2], info)
8888
end
8989
end
9090
if j > length(locstk)

test/branching.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,15 @@ end
221221
""") === 3
222222

223223
end
224+
#-------------------------------------------------------------------------------
225+
# Block condition
226+
@test JuliaLowering.include_string(test_mod, """
227+
let a = true
228+
if begin; x = 2; a; end
229+
x
230+
end
231+
end
232+
""") === 2
224233

225234
#-------------------------------------------------------------------------------
226235
@testset "`&&` and `||` chains" begin

test/functions.jl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,31 @@ end
5656
2^4
5757
""") == 16
5858

59+
#-------------------------------------------------------------------------------
60+
# Arrow syntax
61+
@test JuliaLowering.include_string(test_mod, """
62+
let
63+
f = ((x::T, y::T) where T) -> x + y
64+
f(1, 2)
65+
end
66+
""") === 3
67+
68+
@test JuliaLowering.include_string(test_mod, """
69+
let
70+
f = ((x::T; y=2) where T) -> x + y
71+
f(1)
72+
end
73+
""") === 3
74+
75+
# Passes desugaring, but T is detected as unused and throws an error.
76+
# Is it clear whether this should be `f(x::T) where T` or `f(x::T where T)`?
77+
@test_broken JuliaLowering.include_string(test_mod, """
78+
let
79+
f = ((x::T) where T) -> x
80+
f(1)
81+
end
82+
""") === 1
83+
5984
#-------------------------------------------------------------------------------
6085
# Function definitions
6186
@test JuliaLowering.include_string(test_mod, """

test/typedefs_ir.jl

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,52 @@ end
409409
34 latestworld
410410
35 (return core.nothing)
411411

412+
########################################
413+
# Empty struct with empty ctor
414+
struct X
415+
X() = new()
416+
end
417+
#---------------------
418+
1 (global TestMod.X)
419+
2 latestworld
420+
3 (call core.svec)
421+
4 (call core.svec)
422+
5 (call core.svec)
423+
6 (call core._structtype TestMod :X %%%false 0)
424+
7 (= slot₁/X %₆)
425+
8 (call core._setsuper! %₆ core.Any)
426+
9 (call core.isdefinedglobal TestMod :X false)
427+
10 (gotoifnot %₉ label₁₄)
428+
11 TestMod.X
429+
12 (= slot₂/if_val (call core._equiv_typedef %₁₁ %₆))
430+
13 (goto label₁₅)
431+
14 (= slot₂/if_val false)
432+
15 slot₂/if_val
433+
16 (gotoifnot %₁₅ label₂₀)
434+
17 TestMod.X
435+
18 (= slot₃/if_val %₁₇)
436+
19 (goto label₂₁)
437+
20 (= slot₃/if_val false)
438+
21 slot₃/if_val
439+
22 (gotoifnot %₁₅ label₂₃)
440+
23 (call core.svec)
441+
24 (call core._typebody! %₂₁ %%₂₃)
442+
25 (constdecl TestMod.X %₂₄)
443+
26 latestworld
444+
27 TestMod.X
445+
28 (call core.apply_type core.Type %₂₇)
446+
29 (call core.svec %₂₈)
447+
30 (call core.svec)
448+
31 SourceLocation::2:5
449+
32 (call core.svec %₂₉ %₃₀ %₃₁)
450+
33 --- method core.nothing %₃₂
451+
slots: [slot₁/#ctor-self#]
452+
1 slot₁/#ctor-self#
453+
2 (new %₁)
454+
3 (return %₂)
455+
34 latestworld
456+
35 (return core.nothing)
457+
412458
########################################
413459
# Basic struct
414460
struct X

0 commit comments

Comments
 (0)