Cannot interpolate function signature into function definition expression

This seems to be a parser weakness:

julia> foosig = :( foo(x) )

julia> :( function $foosig 2*x end )
ERROR: syntax: expected "end" in definition of function "($ foosig)"

The error message is miselading: the parser actually wants to see parentheses after $foosig. Note that these related constructions do parse as expected:

julia> :( $foosig = 2*x )
:(foo(x) = 2x)

julia> fooname = :foo

julia> :( function $fooname(x) 2*x end )
:(function foo(x)
      #= none:1 =#

I can replicate on master.

Please check if there is an existing issue for this, and open one if there isn’t.

1 Like

There is an issue that was opened and closed 2 years ago with an argument that the construction in the first example shouldn’t be valid. I added a comment there that I think this issue should be revisited.

1 Like