Skip to content

Commit a63cca8

Browse files
authored
Don't introduce a block around y in parsing x' = y (#60246)
Closes #59911. `'` is generally treated as its own thing in Expr and flisp, but treated as a special type of call in JuliaSyntax. This change makes `x' = y` parse to the <=1.11 `(= (|'| x) y)` instead of wrapping the body in a block like we do when parsing `f(x) = y`. The special case is fine to me given that it's a more understandable parse, and we're hoping to move away from LineNumberNodes in the future anyway. (I think this was the original reason for the block-wrap for `f(x) = y`).
1 parent 3484331 commit a63cca8

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

JuliaSyntax/src/integration/expr.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,8 +538,9 @@ end
538538
elseif k == K"function"
539539
if length(args) > 1
540540
if has_flags(nodehead, SHORT_FORM_FUNCTION_FLAG)
541+
a1 = args[1]
541542
a2 = args[2]
542-
if !@isexpr(a2, :block)
543+
if !@isexpr(a2, :block) && !@isexpr(a1, Symbol("'"))
543544
args[2] = Expr(:block, a2)
544545
end
545546
retexpr.head = :(=)

JuliaSyntax/test/expr.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,12 @@
269269
Expr(:block,
270270
LineNumberNode(3)))
271271

272+
# short-form postfix function shouldn't introduce a block
273+
@test parsestmt("x' = 1") ==
274+
Expr(:(=),
275+
Expr(Symbol("'"), :x),
276+
1)
277+
272278
# `.=` doesn't introduce short form functions
273279
@test parsestmt("f() .= xs") ==
274280
Expr(:(.=), Expr(:call, :f), :xs)

0 commit comments

Comments
 (0)