Deserialization in a Module()

I don’t understand why the code below errors:

 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
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.

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.

Posted issue at Julia.