Callable struct syntax broken on 1.11 -> 1.12
parserfixed on master
on 1.11.9
```julia
julia> struct T end
julia> function (
t::T
)(x, y)
x + y
end
julia> T()(1, 2)
3
```
on 1.12.6
```julia
julia> struct T end
julia> function (
t::T
)(x, y)
x + y
end
#2 (generic function with 1 method)
julia> T()(1, 2)
ERROR: MethodError: objects of type T are not callable
The object of type `T` exists, but no method is defined for this combination of argument types when trying to treat it as a callable object.
Stacktrace:
[1] top-level scope
@ REPL[3]:1
julia> Meta.parse("""
function (
t::T
)(x, y)
x + y
end
""")
:(function (t::T,)
#= none:1 =#
#= none:3 =#
(x, y)
#= none:4 =#
x + y
end)
```
I think this is a JuliaSyntax bug? The below demonstration, where the strings with/without newlines parse completely differently, is with v1.0.2 of JuliaSyntax.
On nightly, JuliaSyntax parses both strings the same way and thus the syntax above works again on nightly. I haven't yet bisected but I imagine there's a commit somewhere that needs to be backported.
```julia
julia> using JuliaSyntax: parseall, GreenNode
julia> # This is what it should be
parseall(GreenNode, """
function (t::T)(x, y)
x + y
end
""")
1:36 │[toplevel]
1:35 │ [function]
1:8 │ function
9:9 │ Whitespace
10:21 │ [call]
10:15 │ [parens]
10:10 │ (
11:14 │ [::]
11:11 │ Identifier ✔
12:13 │ ::
14:14 │ Identifier ✔
15:15 │ )
16:16 │ (
17:17 │ Identifier ✔
18:18 │ ,
19:19 │ Whitespace
20:20 │ Identifier ✔
21:21 │ )
22:32 │ [block]
22:26 │ NewlineWs
27:31 │ [call]
27:27 │ Identifier ✔
28:28 │ Whitespace
29:29 │ Identifier ✔
30:30 │ Whitespace
31:31 │ Identifier ✔
32:32 │ NewlineWs
33:35 │ end
36:36 │ NewlineWs
julia> # This is what it comes out as
parseall(GreenNode, """
function (
t::T
)(x, y)
x + y
end
""")
1:42 │[toplevel]
1:41 │ [function]
1:8 │ function
9:9 │ Whitespace
10:21 │ [tuple]
10:10 │ (
11:15 │ NewlineWs
16:19 │ [::]
16:16 │ Identifier ✔
17:18 │ ::
19:19 │ Identifier ✔
20:20 │ NewlineWs
21:21 │ )
22:38 │ [block]
22:27 │ [tuple]
22:22 │ (
23:23 │ Identifier ✔
24:24 │ ,
25:25 │ Whitespace
26:26 │ Identifier ✔
27:27 │ )
28:32 │ NewlineWs
33:37 │ [call]
33:33 │ Identifier ✔
34:34 │ Whitespace
35:35 │ Identifier ✔
36:36 │ Whitespace
37:37 │ Identifier ✔
38:38 │ NewlineWs
39:41 │ end
42:42 │ NewlineWs
```
关闭于 2026-06-20 3 条评论