# Constraints for \`@generated\` function

**URL:** <https://discourse.julialang.org/t/constraints-for-generated-function/27967>\
**Category:** General Usage\
**Tags:** question\
**Created:** [August 25, 2019, 6:34pm UTC](https://discourse.julialang.org/t/constraints-for-generated-function/27967 "2019-08-25T18:34:19Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![c42f](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/c42f/32/52842_2.png) [@c42f](https://discourse.julialang.org/u/c42f)\
**Post date:** [August 26, 2019, 6:26am UTC](https://discourse.julialang.org/t/constraints-for-generated-function/27967/3 "2019-08-26T06:26:01Z")

</div>

You’ve got the gist of it. To expand a little:

- The _generator_ code (used to build the AST from the argument types) cannot call functions _or methods_ which are defined after the generated function is defined. So you can’t generally call things like trait functions within your generator if they may be overloaded for user defined types. This may eventually be fixed in a future julia version with some sufficiently clever tracking of function dependencies (“backedges”), we will see.
- The _generated_ code (which is invoked on the argument values) can call any function, but it may not define new types. This means it can’t use closures because closures are lowered to new types internally. I believe this may also eventually be fixed, but for now we need to put up with it.

---

_[View the full topic](https://discourse.julialang.org/t/constraints-for-generated-function/27967)._
