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

Function definition order matters with generated functions #20326

Closed
omus opened this issue Jan 30, 2017 · 4 comments
Closed

Function definition order matters with generated functions #20326

omus opened this issue Jan 30, 2017 · 4 comments

Comments

@omus
Copy link
Member

omus commented Jan 30, 2017

Any function that is called within a generated function needs to be defined before the generated function definition otherwise we encounter a MethodError from the world being too new:

julia> f1() = 1
f1 (generic function with 1 method)

julia> @generated function g1()
           v = f1()
           quote
               return $v
           end
       end
g1 (generic function with 1 method)

julia> g1()
1

vs.

julia> @generated function g2()
           v = f2()
           quote
               return $v
           end
       end
g2 (generic function with 1 method)

julia> f2() = 1
f2 (generic function with 1 method)

julia> g2()
ERROR: MethodError: no method matching f2()
The applicable method may be too new: running in world age 21396, while current world is 21397.
Closest candidates are:
  f2() at REPL[5]:1 (method too new to be called from this world context.)
Stacktrace:
 [1] g2(...) at ./REPL[4]:2

Introduced with #17057

@omus
Copy link
Member Author

omus commented Jan 30, 2017

cc: @vtjnash

@yuyichao
Copy link
Contributor

I believe this is documented.

@yuyichao
Copy link
Contributor

Basically dup of #19942. Closing this and any discussion about it can continue on that issue.

@omus
Copy link
Member Author

omus commented Jan 30, 2017

For completeness. Documented in Metaprogramming:

Some operations that should not be attempted include:
....
Calling any function that is defined after the body of the generated function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants