Skip to content

Commit 86eff5d

Browse files
authored
Merge pull request #336 from julia-vscode/sp/mutable-struct-const-bindings
Properly mark bindings for const-fields in mutable structs
2 parents 7b45261 + a58a482 commit 86eff5d

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/bindings.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,9 @@ function mark_bindings!(x::EXPR, state)
100100
end
101101
mark_parameters(CSTParser.get_sig(x))
102102
if CSTParser.defines_struct(x) # mark field block
103-
for i in 1:length(x.args[3].args)
104-
CSTParser.defines_function(x.args[3].args[i]) && continue
105-
arg = x.args[3].args[i]
106-
if kwdef && CSTParser.isassignment(arg)
103+
for arg in x.args[3].args
104+
CSTParser.defines_function(arg) && continue
105+
if kwdef && CSTParser.isassignment(arg) || arg.head === :const
107106
arg = arg.args[1]
108107
end
109108
mark_binding!(arg)

test/runtests.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,17 @@ function f(arg::T)
155155
end
156156
""") == [true, true, true, true, true, true, true]
157157

158+
if VERSION > v"1.8-"
159+
@test check_resolved("""
160+
mutable struct T
161+
const field
162+
end
163+
function f(arg::T)
164+
arg.field
165+
end
166+
""") == [true, true, true, true, true, true, true]
167+
end
168+
158169
@test check_resolved("""
159170
f(arg) = arg
160171
""") == [1, 1, 1]

0 commit comments

Comments
 (0)