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

get(::Dict{DataType,T}, key, default) fails to get the right value #40521

Closed
yeesian opened this issue Apr 18, 2021 · 2 comments
Closed

get(::Dict{DataType,T}, key, default) fails to get the right value #40521

yeesian opened this issue Apr 18, 2021 · 2 comments

Comments

@yeesian
Copy link

yeesian commented Apr 18, 2021

The following command fails on the macOS binary for Julia 1.6:

  | | |_| | | | (_| |  |  Version 1.6.0 (2021-03-24)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> get(Dict{DataType,Integer}(
           Any         => 0,
           UInt8       => 1), UInt8, error("Unknown DataType"))
ERROR: Unknown DataType
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:33
 [2] top-level scope
   @ REPL[1]:1

It works if it's indexed directly (per https://discourse.julialang.org/t/using-datatype-as-key-in-dict ):

julia> Dict{DataType,Integer}(
                  Any         => 0,
                  UInt8       => 1)[UInt8]
1

If it helps for motivation/context: I was looking into not using the indexing behavior due to yeesian/ArchGDAL.jl#178.

@simeonschaub
Copy link
Member

The arguments to any function call are always evaluated first, so this behavior is expected. get does have a method accepting a function as the first argument though for exactly this use case: https://docs.julialang.org/en/v1/base/collections/#Base.get

@yeesian
Copy link
Author

yeesian commented Apr 18, 2021

The arguments to any function call are always evaluated first, so this behavior is expected.

That makes sense, thanks for the explanation!

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