# Issue with using @show in generated functions

**URL:** <https://discourse.julialang.org/t/issue-with-using-show-in-generated-functions/16721>\
**Category:** General Usage\
**Created:** [October 24, 2018, 9:18am UTC](https://discourse.julialang.org/t/issue-with-using-show-in-generated-functions/16721 "2018-10-24T09:18:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aashish01](https://avatars.discourse-cdn.com/v4/letter/a/8dc957/32.png) [@aashish01](https://discourse.julialang.org/u/aashish01)\
**Post date:** [October 24, 2018, 9:18am UTC](https://discourse.julialang.org/t/issue-with-using-show-in-generated-functions/16721/1 "2018-10-24T09:18:00Z")

</div>

I had written a generated function of the following form and used @show to see the final code being generated.

```julia
@generated function deserialize!(buffer, ::TypeHolder{T}) where T <: NSE_composites
    ops = [:(retval.$f = deserialize!(buffer, TypeHolder{$t}())) for (f,t) in collect(zip(fieldnames(T), T.types))]
    pushfirst!(ops, :(retval = T())) 
    push!(ops, :(return retval)) 
    ex = Expr(:block, ops...)
    @show ex
    return ex
end

```

Now the above code worked perfectly and did not give me any issues. However later when it was called by a an async task, the code crashed with the following error

> task switch not allowed from inside staged nor pure functions

After checking some [issues](https://github.com/JuliaLang/julia/issues/18568) on github issues, I figured that this is because of calls to @show. Removing @show does solve the error.

Could someone explain what happened here, and should we avoid println and @show in generated functions always?

---

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [October 24, 2018, 9:23am UTC](https://discourse.julialang.org/t/issue-with-using-show-in-generated-functions/16721/2 "2018-10-24T09:23:43Z")

</div>

There are certain forbidden things in generated functions. They are listed in the [relevant docs section](https://docs.julialang.org/en/v1/manual/metaprogramming/index.html#Generated-functions-1), fourth point in the list.
