# Deserialization in a Module()

**URL:** https://discourse.julialang.org/t/deserialization-in-a-module/115577
**Category:** General Usage
**Tags:** literate
**Created:** [June 12, 2024, 10:54pm UTC](https://discourse.julialang.org/t/deserialization-in-a-module/115577 "2024-06-12T22:54:45Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![ablaom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ablaom/32/4889_2.png) [@ablaom](https://discourse.julialang.org/u/ablaom)
#### Post date: [June 12, 2024, 10:54pm UTC](https://discourse.julialang.org/t/deserialization-in-a-module/115577/1 "2024-06-12T22:54:45Z")

</div>

I don’t understand why the code below errors:

```julia
 module TestMod
       
       MyMod = Module()
       Core.eval(
           MyMod,
           quote
               using Serialization
               f() = "hello"
               const TARGET = joinpath(tempdir(), "greeter.jls")
               serialize(TARGET, f)
           end,
       )
       
       Core.eval(
           MyMod,
           quote
               g = deserialize(TARGET)
               print(g())
           end,
       )
       
       end

end

```

```julia
ERROR: UndefVarError: `anonymous` not defined
Stacktrace:
  [1] deserialize_module(s::Serialization.Serializer{IOStream})
    @ Serialization /Applications/Julia-

    < omitted detail >

 [14] deserialize(filename::String)
    @ Serialization /Applications/Julia-1.10.app/Contents/Resources/julia/share/julia/stdlib/v1.10/Serialization/src/Serialization.jl:811                      
 [15] top-level scope
    @ REPL[18]:17
 [16] eval(m::Module, e::Any)
    @ Core ./boot.jl:385
 [17] top-level scope
    @ REPL[18]:14

```

Here `anonymous` is the default name given by `Module()`, ie, `Module()` is the same as `Module(:anonymous)`.

Context: I have run into what looks like a “bug” in Literate.jl when the source code contains deserialisation. But on consulting with @asinghvi17 , he suggested the above MWE which indeed reproduces the same kind of error.

---

<div class="post-metadata">

### Author: ![asinghvi17](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/asinghvi17/32/8272_2.png) [@asinghvi17](https://discourse.julialang.org/u/asinghvi17)
#### Post date: [June 12, 2024, 11:01pm UTC](https://discourse.julialang.org/t/deserialization-in-a-module/115577/2 "2024-06-12T23:01:00Z")

</div>

The MWE also causes errors when not wrapped in a module, i.e. executed directly from Main.

That being said, I can’t replicate this if `f` is not a function. That is to say, replacing `f()` with `f` and `g()` with `g` makes this work. That might point to a clearer specification of what’s going wrong.

---

<div class="post-metadata">

### Author: ![ablaom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ablaom/32/4889_2.png) [@ablaom](https://discourse.julialang.org/u/ablaom)
#### Post date: [June 16, 2024, 8:11pm UTC](https://discourse.julialang.org/t/deserialization-in-a-module/115577/3 "2024-06-16T20:11:35Z")

</div>

Posted [issue](https://github.com/JuliaLang/julia/issues/54827) at Julia.
