Skip to content

Commit a80b038

Browse files
authored
Fix = to kw conversion in x[a, b; i=j] (#173)
1 parent 55e84b7 commit a80b038

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/expr.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function reorder_parameters!(args, params_pos)
3131
end
3232

3333
function _to_expr(node::SyntaxNode; iteration_spec=false, need_linenodes=true,
34-
eq_to_kw=false, inside_vect_or_braces=false)
34+
eq_to_kw=false, map_kw_in_params=false)
3535
if !haschildren(node)
3636
val = node.val
3737
if val isa Union{Int128,UInt128,BigInt}
@@ -131,8 +131,8 @@ function _to_expr(node::SyntaxNode; iteration_spec=false, need_linenodes=true,
131131
eq_to_kw_in_call =
132132
((headsym == :call || headsym == :dotcall) && is_prefix_call(node)) ||
133133
headsym == :ref
134-
eq_to_kw_all = headsym == :parameters && !inside_vect_or_braces
135-
in_vb = headsym == :vect || headsym == :braces
134+
eq_to_kw_all = headsym == :parameters && !map_kw_in_params
135+
in_vbr = headsym == :vect || headsym == :braces || headsym == :ref
136136
if insert_linenums && isempty(node_args)
137137
push!(args, source_location(LineNumberNode, node.source, node.position))
138138
else
@@ -144,7 +144,7 @@ function _to_expr(node::SyntaxNode; iteration_spec=false, need_linenodes=true,
144144
eq_to_kw = eq_to_kw_in_call && i > 1 || eq_to_kw_all
145145
args[insert_linenums ? 2*i : i] =
146146
_to_expr(n, eq_to_kw=eq_to_kw,
147-
inside_vect_or_braces=in_vb)
147+
map_kw_in_params=in_vbr)
148148
end
149149
end
150150
end

test/expr.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@
208208
# ref
209209
@test parse(Expr, "x[i=j]") ==
210210
Expr(:ref, :x, Expr(:kw, :i, :j))
211+
@test parse(Expr, "x[a, b; i=j]") ==
212+
Expr(:ref, :x, Expr(:parameters, Expr(:(=), :i, :j)), :a, :b)
211213

212214
# vect/braces
213215
@test parse(Expr, "[a=1,; b=2]") ==

0 commit comments

Comments
 (0)