What is wrong with getfield?


module RRW
  struct YU
  end
end

const modsym = RRW

getfield(modsym,:YU)

ERROR: UndefVarError: YU not defined

this doesn’t happen when i do the following:

getfield(RRW,:YU)
RRW.YU

Why does this happen?

               _
   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation: https://docs.julialang.org
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.7.0-beta.115 (2018-07-02 03:32 UTC)
 _/ |\__'_|_|_|\__'_|  |  Commit b7dc60f7b4* (0 days old master)
|__/                   |  x86_64-apple-darwin16.7.0

julia> module RRW
       struct YU
       end
       end
Main.RRW

julia> const modsym = RRW
Main.RRW

julia> getfield(modsym, :YU)
Main.RRW.YU

interesting, then this is happening only in v0.6
is there a work around for this in v0.6?

   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation: https://docs.julialang.org
   _ _   _| |_  __ _   |  Type "?help" for help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.6.2 (2017-12-13 18:08 UTC)
 _/ |\__'_|_|_|\__'_|  |  Official http://julialang.org/ release
|__/                   |  x86_64-pc-linux-gnu

Thanks

Works fine on 0.6.3 as well, so maybe just upgrade to that if it’s not working on 0.6.2?

1 Like