Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Macro hygiene problems with function return type and where #21581

Closed
TotalVerb opened this issue Apr 27, 2017 · 0 comments · Fixed by #22166
Closed

Macro hygiene problems with function return type and where #21581

TotalVerb opened this issue Apr 27, 2017 · 0 comments · Fixed by #22166
Assignees
Labels
bug Indicates an unexpected problem or unintended behavior compiler:lowering Syntax lowering (compiler front end, 2nd stage)

Comments

@TotalVerb
Copy link
Contributor

TotalVerb commented Apr 27, 2017

OK:

julia> module Foo
           macro bar()
               :(foo(x) = x; foo(1))
           end
       end
Foo

julia> Foo.@bar
1

julia> macroexpand(:(Foo.@bar))
quote 
    #3#foo(#4#x) = begin  # REPL[1], line 3:
            #4#x
        end
    #3#foo(1)
end

Problem:

julia> module Foo2
           macro bar()
               :(foo(x)::Int = x; foo(1))
           end
       end
Foo2

julia> Foo2.@bar
ERROR: syntax: "Foo2.x" is not a valid function argument name

julia> macroexpand(:(Foo2.@bar))
quote 
    (Foo2.foo)(Foo2.x)::Foo2.Int = Foo2.x
    (Foo2.foo)(1)
end

Related problems manifest in other cases:

julia> global function foo(x)::Int
       end
ERROR: syntax: invalid syntax in "global" declaration

julia> global function foo(x)
       end
foo (generic function with 1 method)

In general I think there are several places that need to be updated for (function (:: ,ex ,rettype) ,body) and (function (where ,ex ,ex2) ,body) syntax.

Some of the sites I identified are

macroexpand.scm

julia-syntax.scm

I would make a PR, but I'm a little reluctant to because I don't know if simply adding cases for where and :: to each of the above sites is the best solution.

@JeffBezanson JeffBezanson added the compiler:lowering Syntax lowering (compiler front end, 2nd stage) label Apr 27, 2017
@JeffBezanson JeffBezanson self-assigned this May 31, 2017
@JeffBezanson JeffBezanson added the bug Indicates an unexpected problem or unintended behavior label May 31, 2017
JeffBezanson added a commit that referenced this issue May 31, 2017
JeffBezanson added a commit that referenced this issue Jun 1, 2017
JeffBezanson added a commit that referenced this issue Jun 1, 2017
JeffBezanson added a commit that referenced this issue Jun 1, 2017
tkelman pushed a commit that referenced this issue Jun 3, 2017
fixes #22135, fixes #22122, fixes #22026, fixes #21581, fixes #16096, fixes #19351

(cherry picked from commit 60675d2)
ref #22166
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior compiler:lowering Syntax lowering (compiler front end, 2nd stage)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants