Skip to content

Commit 0ff1b8c

Browse files
committed
fix: tweak type handling to work on 1.12
1 parent f7008ed commit 0ff1b8c

File tree

4 files changed

+32
-18
lines changed

4 files changed

+32
-18
lines changed

src/bindings.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Binding(name, val, type, refs) = Binding(name, val, type, refs, false)
1919
function Base.show(io::IO, b::Binding)
2020
printstyled(io, " Binding(", to_codeobject(b.name),
2121
b.is_public ? "" : "",
22-
b.type === nothing ? "" : "::($(b.type))",
22+
b.type === nothing ? "" : "::($(b.type.name))",
2323
b.refs isa Vector ? " ($(length(b.refs)) refs))" : ")", color=:blue)
2424
end
2525

src/linting/checks.jl

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -431,15 +431,15 @@ end
431431

432432
function check_nothing_equality(x::EXPR, env::ExternalEnv)
433433
if isbinarycall(x) && length(x.args) == 3
434-
nothings = (getsymbols(env)[:Core][:nothing], getsymbols(env)[:Base][:nothing])
434+
_nothing = getsymbols(env)[:Core][:nothing]
435435
if valof(x.args[1]) == "==" && (
436-
(valof(x.args[2]) == "nothing" && refof(x.args[2]) in nothings) ||
437-
(valof(x.args[3]) == "nothing" && refof(x.args[3]) in nothings)
436+
(valof(x.args[2]) == "nothing" && refof(x.args[2]) == _nothing) ||
437+
(valof(x.args[3]) == "nothing" && refof(x.args[3]) == _nothing)
438438
)
439439
seterror!(x.args[1], NothingEquality)
440440
elseif valof(x.args[1]) == "!=" && (
441-
(valof(x.args[2]) == "nothing" && refof(x.args[2]) in nothings) ||
442-
(valof(x.args[3]) == "nothing" && refof(x.args[3]) in nothings)
441+
(valof(x.args[2]) == "nothing" && refof(x.args[2]) == _nothing) ||
442+
(valof(x.args[3]) == "nothing" && refof(x.args[3]) == _nothing)
443443
)
444444
seterror!(x.args[1], NothingNotEq)
445445
end
@@ -512,7 +512,9 @@ function is_never_datatype(b::Binding, env::ExternalEnv)
512512
elseif CoreTypes.isdatatype(b.type)
513513
return false
514514
elseif b.type !== nothing
515-
return true
515+
if !any(x -> x isa SymbolServer.DataTypeStore, get_eventual_datatype(ref, env) for ref in b.refs)
516+
return true
517+
end
516518
end
517519
return false
518520
end
@@ -878,7 +880,7 @@ UInt64, UInt128`.
878880
"""
879881
function check_kw_default(x::EXPR, env::ExternalEnv)
880882
if headof(x) == :kw && isdeclaration(x.args[1]) && CSTParser.isliteral(x.args[2]) && hasref(x.args[1].args[2])
881-
decl_T = refof(x.args[1].args[2])
883+
decl_T = get_eventual_datatype(refof(x.args[1].args[2]), env)
882884
rhs = x.args[2]
883885
rhsval = valof(rhs)
884886
if decl_T == getsymbols(env)[:Core][:String] && !CSTParser.isstringliteral(rhs)

src/type_inf.jl

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ function infer_type_assignment_rhs(binding, state, scope)
3737
lhs = binding.val.args[1]
3838
rhs = binding.val.args[2]
3939
if is_loop_iter_assignment(binding.val)
40-
settype!(binding, infer_eltype(rhs))
40+
settype!(binding, infer_eltype(rhs, state))
4141
elseif headof(rhs) === :ref && length(rhs.args) > 1
4242
ref = refof_maybe_getfield(rhs.args[1])
4343
if ref isa Binding && ref.val isa EXPR
44-
settype!(binding, infer_eltype(ref.val))
44+
settype!(binding, infer_eltype(ref.val, state))
4545
end
4646
else
4747
if CSTParser.is_func_call(rhs)
@@ -147,11 +147,20 @@ function infer_type_decl(binding, state, scope)
147147
else
148148
settype!(binding, refof(t))
149149
end
150-
elseif refof(t) isa SymbolServer.DataTypeStore
151-
settype!(binding, refof(t))
150+
else
151+
edt = get_eventual_datatype(refof(t), state.server.external_env)
152+
if edt !== nothing
153+
settype!(binding, edt)
154+
end
152155
end
153156
end
154157

158+
get_eventual_datatype(_, _::ExternalEnv) = nothing
159+
get_eventual_datatype(b::SymbolServer.DataTypeStore, _::ExternalEnv) = b
160+
function get_eventual_datatype(b::SymbolServer.FunctionStore, env::ExternalEnv)
161+
return SymbolServer._lookup(b.extends, getsymbols(env))
162+
end
163+
155164
# Work out what type a bound variable has by functions that are called on it.
156165
function infer_type_by_use(b::Binding, env::ExternalEnv)
157166
b.type !== nothing && return # b already has a type
@@ -284,19 +293,22 @@ end
284293
# Assumes x.head.val == "="
285294
is_loop_iter_assignment(x::EXPR) = x.parent isa EXPR && ((x.parent.head == :for || x.parent.head == :generator) || (x.parent.head == :block && x.parent.parent isa EXPR && (x.parent.parent.head == :for || x.parent.parent.head == :generator)))
286295

287-
function infer_eltype(x::EXPR)
296+
function infer_eltype(x::EXPR, state)
288297
if isidentifier(x) && hasref(x) # assume is IDENT
289298
r = refof(x)
290299
if r isa Binding && r.val isa EXPR
291300
if isassignment(r.val) && r.val.args[2] != x
292-
return infer_eltype(r.val.args[2])
301+
return infer_eltype(r.val.args[2], state)
293302
end
294303
end
295304
elseif headof(x) === :ref && hasref(x.args[1])
296305
r = refof(x.args[1])
297-
if r isa SymbolServer.DataTypeStore ||
298-
r isa Binding && CoreTypes.isdatatype(r.type)
299-
r
306+
if r isa Binding && CoreTypes.isdatatype(r.type)
307+
return r
308+
end
309+
edt = get_eventual_datatype(r, state.server.external_env)
310+
if edt isa SymbolServer.DataTypeStore
311+
return edt
300312
end
301313
elseif headof(x) === :STRING
302314
return CoreTypes.Char

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2188,7 +2188,7 @@ end
21882188
end
21892189
21902190
end""")
2191-
@test refof(cst.args[1].args[3].args[3].args[3].args[2]) !== nothing
2191+
@test refof(cst.args[1].args[3].args[3].args[1]) !== nothing
21922192
@test refof(cst.args[1].args[3].args[4].args[1]).is_public
21932193
@test StaticLint.refof(cst.args[1].args[3].args[5].args[3].args[3].args[2].args[1]).is_public
21942194
end

0 commit comments

Comments
 (0)