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

at-kwdef not working with const fields #45573

Closed
garborg opened this issue Jun 3, 2022 · 1 comment · Fixed by #46276
Closed

at-kwdef not working with const fields #45573

garborg opened this issue Jun 3, 2022 · 1 comment · Fixed by #46276

Comments

@garborg
Copy link
Contributor

garborg commented Jun 3, 2022

using Base: @kwdef

@kwdef struct Foo
    a::Int
    b::Int=2
end
@kwdef mutable struct Bar
    a::Int
    b::Int=2
end
@kwdef mutable struct Baz
    const a::Int
    b::Int=2
end

a = 1
Foo(; a) # => Foo(1, 2)
Bar(; a) # => Bar(1, 2)
Baz(; a) # =>
# ERROR: MethodError: no method matching Baz(; a=1)
# Closest candidates are:
#   Baz(; b) at util.jl:493 got unsupported keyword argument "a"
#   Baz(::Int64, ::Int64) at Untitled-1:10 got unsupported keyword argument "a"
#   Baz(::Any, ::Any) at Untitled-1:10 got unsupported keyword argument "a"
# Stacktrace:
#  [1] kwerr(kw::NamedTuple{(:a,), Tuple{Int64}}, args::Type)
#    @ Base ./error.jl:165
#  [2] top-level scope
#    @ Untitled-1:16
julia> versioninfo()
Julia Version 1.8.0-rc1
Commit 6368fdc656 (2022-05-27 18:33 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: 2 × Intel(R) Xeon(R) CPU E5-2680 v4 @ 2.40GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-13.0.1 (ORCJIT, sandybridge)
  Threads: 1 on 2 virtual cores
Environment:
  JULIA_EDITOR = code
  JULIA_NUM_THREADS = 
@giordano
Copy link
Contributor

giordano commented Jun 3, 2022

I guess it's related to #45020

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

Successfully merging a pull request may close this issue.

2 participants