Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessing field N of Vararg{T} is an undefined access on Julia 1.7 #41724

Closed
darsnack opened this issue Jul 29, 2021 · 1 comment
Closed

Accessing field N of Vararg{T} is an undefined access on Julia 1.7 #41724

darsnack opened this issue Jul 29, 2021 · 1 comment

Comments

@darsnack
Copy link

I ran into this trying to fix BSON.jl: JuliaIO/BSON.jl#102.

julia> versioninfo()
Julia Version 1.6.0
Commit f9720dc2eb (2021-03-24 12:55 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin19.6.0)
  CPU: Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-11.0.1 (ORCJIT, skylake)
Environment:
  JULIA_NUM_THREADS = 4

julia> x = Vararg{Any}
Vararg{Any, N} where N

julia> fieldnames(typeof(x))
(:var, :body)

julia> x.var
N

julia> x.body
Vararg{Any, N}
julia> versioninfo()
Julia Version 1.7.0-beta3.0
Commit e76c9dad42 (2021-07-07 08:12 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin18.7.0)
  CPU: Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.0 (ORCJIT, skylake)
Environment:
  JULIA_NUM_THREADS = 4

julia> x = Vararg{Any}
Vararg{Any}

julia> fieldnames(typeof(x))
(:T, :N)

julia> x.T
Any

julia> x.N
ERROR: UndefRefError: access to undefined reference
Stacktrace:
 [1] getproperty(x::Core.TypeofVararg, f::Symbol)
   @ Base ./Base.jl:42
 [2] top-level scope
   @ REPL[48]:1

I'm not sure what the correct fix here should be w.r.t. BSON.jl, but it seems like accessing x.N should not error or fieldnames(typeof(x)) should not contain :N.

@JeffBezanson
Copy link
Member

The N field exists but is undefined when the length is unspecified. In general objects can have undefined fields, so that needs to be handled by any code that looks at object fields generically. For example

julia> struct X
       field
       X() = new()
       end

julia> X().field
ERROR: UndefRefError: access to undefined reference

julia> fieldnames(X)
(:field,)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants