Skip to content

fix: handle kwdef mutable const correctly #384

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

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/bindings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ function mark_bindings!(x::EXPR, state)
if CSTParser.defines_struct(x) # mark field block
for arg in x.args[3].args
CSTParser.defines_function(arg) && continue
if kwdef && CSTParser.isassignment(arg) || arg.head === :const
if arg.head === :const
arg = arg.args[1]
end
if kwdef && CSTParser.isassignment(arg)
arg = arg.args[1]
end
mark_binding!(arg)
Expand Down
18 changes: 18 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,24 @@ f(arg) = arg
""")
@test StaticLint.errorof(cst[2]) === nothing
end
if VERSION >= v"1.10"
let cst = parse_and_pass("""
@kwdef mutable struct A
const x::Float64
end
A(x = 5.0)
""")
@test StaticLint.errorof(cst[2]) === nothing
end
let cst = parse_and_pass("""
@kwdef mutable struct A
const x::Float64 = 1.0
end
A(x = 5.0)
""")
@test StaticLint.errorof(cst[2]) === nothing
end
end
let cst = parse_and_pass("""
import Base: sin
\"\"\"
Expand Down