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

isdefined fails for Int32 index #30648

Closed
joachimdahl opened this issue Jan 8, 2019 · 4 comments · Fixed by #30697
Closed

isdefined fails for Int32 index #30648

joachimdahl opened this issue Jan 8, 2019 · 4 comments · Fixed by #30697
Assignees
Labels
docs This change adds or pertains to documentation

Comments

@joachimdahl
Copy link
Contributor

joachimdahl commented Jan 8, 2019

This is probably unintended behaviour.

julia> versioninfo()
Julia Version 1.0.3
Commit 099e826241 (2018-12-18 01:34 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Xeon(R) CPU E5-2470 v2 @ 2.40GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.0 (ORCJIT, ivybridge)

julia> isdefined(Array{Any}(undef,1),Int64(1))
false

julia> isdefined(Array{Any}(undef,1),Int32(1))
ERROR: TypeError: in isdefined, expected Symbol, got Int32
Stacktrace:
 [1] top-level scope at none:0


@andreasnoack
Copy link
Member

Indices are restricted to Int in many functions. That limits the number of specializations. We have discussed this a couple of times and I'm not sure what our current thinking is wrt to allowing more input types.

@JeffBezanson
Copy link
Member

See the description of isdefined:

    isdefined(m::Module, s::Symbol)
    isdefined(object, s::Symbol)
    isdefined(object, index::Int)

Tests whether an assignable location is defined. The arguments can be a module and a symbol
or a composite object and field name (as a symbol) or index.

In other words, it only works on modules or object fields, not array elements. Arrays use isassigned.

@mbauman
Copy link
Member

mbauman commented Jan 8, 2019

Right, it won't do what you want even if you passed it Int indices, either:

julia> isdefined(Any[1], 1)
false

IMO this is all the more reason it shouldn't do the array-like to_indices conversion of that index.
Perhaps the docstring should point to isassigned to make this a bit clearer?

@JeffBezanson
Copy link
Member

+1 to linking docs to isassigned.

@JeffBezanson JeffBezanson added the docs This change adds or pertains to documentation label Jan 8, 2019
@JeffBezanson JeffBezanson self-assigned this Jan 11, 2019
JeffBezanson added a commit that referenced this issue Jan 11, 2019
fix #29244, document `Expr`
fix #30648, link `isdefined` to `isassigned`
update docstring for `macro`
fix variable scope description in manual
JeffBezanson added a commit that referenced this issue Jan 12, 2019
fix #29244, document `Expr`
fix #30648, link `isdefined` to `isassigned`
update docstring for `macro`
fix variable scope description in manual
KristofferC pushed a commit that referenced this issue Feb 11, 2019
fix #29244, document `Expr`
fix #30648, link `isdefined` to `isassigned`
update docstring for `macro`
fix variable scope description in manual

(cherry picked from commit 0ecaffb)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs This change adds or pertains to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants