# Why does println break @generated functions?

**URL:** <https://discourse.julialang.org/t/why-does-println-break-generated-functions/15344>\
**Category:** General Usage\
**Tags:** question\
**Created:** [September 22, 2018, 5:17pm UTC](https://discourse.julialang.org/t/why-does-println-break-generated-functions/15344 "2018-09-22T17:17:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)\
**Post date:** [September 22, 2018, 5:17pm UTC](https://discourse.julialang.org/t/why-does-println-break-generated-functions/15344/1 "2018-09-22T17:17:18Z")

</div>

I’m trying to debug JLD2, but can’t find the line that breaks.

I think it’s somewhere in a `@generated` function, but adding println’s to it breaks everything.

i.e. I get this error message:

```julia
task switch not allowed from inside staged nor pure functions

```

* * *

The function in question is:

- [https://github.com/simonster/JLD2.jl/blob/ae0345682a3b1d256a81de2957623b64ffb405b1/src/data.jl#L1230-L1318](https://github.com/simonster/JLD2.jl/blob/ae0345682a3b1d256a81de2957623b64ffb405b1/src/data.jl#L1230-L1318)

And a relevant gif is:

![](https://global.discourse-cdn.com/julialang/original/3X/7/6/7640f2b2ba5a49be8b8d5afc3b25c742db0f9483.gif)

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [September 22, 2018, 5:24pm UTC](https://discourse.julialang.org/t/why-does-println-break-generated-functions/15344/2 "2018-09-22T17:24:23Z")

</div>

Use `Core.print`.

---

<div class="post-metadata">

**Author:** ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)\
**Post date:** [September 22, 2018, 5:27pm UTC](https://discourse.julialang.org/t/why-does-println-break-generated-functions/15344/3 "2018-09-22T17:27:08Z")

</div>

Thanks @kristoffer.carlsson!

Do you know why `Core.println` doesn’t work anymore?

// gonna link to this on the relevant [github issue](https://github.com/JuliaLang/julia/issues/18568) for future lost souls

**edit:** ignore this. had a typo that prevented a revise reload

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [September 22, 2018, 5:33pm UTC](https://discourse.julialang.org/t/why-does-println-break-generated-functions/15344/4 "2018-09-22T17:33:50Z")

</div>

It should.

```julia
julia> @generated function f(a)
           Core.println(a)
           nothing
       end
f (generic function with 1 method)

julia> f(1)
Int64

```
