From 42555978ae956294e39afdb0526246daa0c61db5 Mon Sep 17 00:00:00 2001 From: Sebastian Pfitzner Date: Fri, 5 Apr 2024 14:58:20 +0200 Subject: [PATCH] fix: handle kwdef mutable const correctly --- src/bindings.jl | 5 ++++- test/runtests.jl | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/bindings.jl b/src/bindings.jl index f7a7dcc8..8efa53a2 100644 --- a/src/bindings.jl +++ b/src/bindings.jl @@ -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) diff --git a/test/runtests.jl b/test/runtests.jl index f752ea89..459385d6 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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 \"\"\"