Skip to content

Commit 22410e6

Browse files
committed
add additional block scope in kwargs to match ref parser
1 parent 88fd0c2 commit 22410e6

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

src/components/internals.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,10 @@ function parse_comma_sep(ps::ParseState, args::Vector{EXPR}, trivia::Vector{EXPR
152152
@nocloser ps :inwhere @nocloser ps :newline @closer ps :comma while !closer(ps)
153153
a = parse_expression(ps)
154154
if kw && _do_kw_convert(ps, a)
155-
a = _kw_convert(a)
155+
b = _do_block_convert(a)
156+
a = _kw_convert(a, b)
156157
end
158+
157159
push!(args, a)
158160
if iscomma(ps.nt)
159161
if istuple

src/utils.jl

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -607,12 +607,24 @@ Should `a` be converted to a keyword-argument expression?
607607
"""
608608
_do_kw_convert(ps::ParseState, a::EXPR) = !ps.closer.brace && isassignment(a)
609609

610+
_do_block_convert(a::EXPR) =
611+
a.args[1] !== nothing && isoperator(a.args[1].head) && a.args[1].args !== nothing && a.args[1].args[1].head === :call
612+
610613
"""
611-
_kw_convert(ps::ParseState, a::EXPR)
614+
_kw_convert(a::EXPR, blockwrap = false)
612615
613616
Converted an assignment expression to a keyword-argument expression.
614617
"""
615-
_kw_convert(x::EXPR) = EXPR(:kw, EXPR[x.args[1], x.args[2]], EXPR[x.head], x.fullspan, x.span)
618+
_kw_convert(x::EXPR, blockwrap = false) = EXPR(
619+
:kw,
620+
EXPR[
621+
x.args[1],
622+
# in some specific cases, the reference parser wraps the RHS of kwargs in an extra block
623+
blockwrap ?
624+
EXPR(:block, EXPR[x.args[2]], EXPR[], x.args[2].fullspan, x.args[2].span) :
625+
x.args[2]
626+
],
627+
EXPR[x.head], x.fullspan, x.span)
616628

617629
"""
618630
convertsigtotuple(sig::EXPR)

test/test_check_base.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@
160160
# CSTParser does not support right now. This does not mean that we
161161
# cannot parse that file though, just that Expr conversion doesn't
162162
# work well
163-
if v"1.10-" <= VERSION < v"1.11-" && basename(file) == "syntax.jl"
163+
if v"1.10-" <= VERSION < v"1.12-" && basename(file) == "syntax.jl"
164164
@test_broken false
165165
else
166166
@test false

test/test_spec.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ end
9191
include("shared.jl")
9292

9393
test_expr("f(a=1)", :call, 4, false)
94+
test_expr("f(::typeof(a)=1)", :call, 4, false)
95+
test_expr("f(a::typeof(a)=1)", :call, 4, false)
96+
test_expr("f(::a=1)", :call, 4, false)
97+
test_expr("f(a::a=1)", :call, 4, false)
98+
99+
test_expr("f(; a::typeof(a)=1)", :call, 4, false)
100+
test_expr("f(; a::a=1)", :call, 4, false)
94101
end
95102

96103
@testitem ":tuple" begin

0 commit comments

Comments
 (0)