Skip to content

Commit

Permalink
fix: handle kwdef mutable const correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
pfitzseb committed Apr 5, 2024
1 parent 0b846cc commit 4255597
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
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

0 comments on commit 4255597

Please sign in to comment.