Skip to content

Commit dd68524

Browse files
authored
Merge pull request #384 from julia-vscode/sp/kwdef-const
fix: handle kwdef mutable const correctly
2 parents 0b846cc + 4255597 commit dd68524

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/bindings.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,10 @@ function mark_bindings!(x::EXPR, state)
102102
if CSTParser.defines_struct(x) # mark field block
103103
for arg in x.args[3].args
104104
CSTParser.defines_function(arg) && continue
105-
if kwdef && CSTParser.isassignment(arg) || arg.head === :const
105+
if arg.head === :const
106+
arg = arg.args[1]
107+
end
108+
if kwdef && CSTParser.isassignment(arg)
106109
arg = arg.args[1]
107110
end
108111
mark_binding!(arg)

test/runtests.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,24 @@ f(arg) = arg
606606
""")
607607
@test StaticLint.errorof(cst[2]) === nothing
608608
end
609+
if VERSION >= v"1.10"
610+
let cst = parse_and_pass("""
611+
@kwdef mutable struct A
612+
const x::Float64
613+
end
614+
A(x = 5.0)
615+
""")
616+
@test StaticLint.errorof(cst[2]) === nothing
617+
end
618+
let cst = parse_and_pass("""
619+
@kwdef mutable struct A
620+
const x::Float64 = 1.0
621+
end
622+
A(x = 5.0)
623+
""")
624+
@test StaticLint.errorof(cst[2]) === nothing
625+
end
626+
end
609627
let cst = parse_and_pass("""
610628
import Base: sin
611629
\"\"\"

0 commit comments

Comments
 (0)