Skip to content

Commit 9c99454

Browse files
KristofferCaviatesk
authored andcommitted
fix some issues discovered by JET (#48303)
1 parent 5da6d97 commit 9c99454

File tree

9 files changed

+44
-35
lines changed

9 files changed

+44
-35
lines changed

base/binaryplatforms.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ function detect_libstdcxx_version(max_minor_version::Int=30)
872872
end
873873

874874
# Brute-force our way through GLIBCXX_* symbols to discover which version we're linked against
875-
hdl = Libdl.dlopen(first(libstdcxx_paths))
875+
hdl = Libdl.dlopen(first(libstdcxx_paths))::Ptr{Cvoid}
876876
# Try all GLIBCXX versions down to GCC v4.8:
877877
# https://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html
878878
for minor_version in max_minor_version:-1:18

base/loading.jl

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,11 @@ function explicit_manifest_uuid_path(project_file::String, pkg::PkgId)::Union{No
865865
uuid = get(entry, "uuid", nothing)::Union{Nothing, String}
866866
extensions = get(entry, "extensions", nothing)::Union{Nothing, Dict{String, Any}}
867867
if extensions !== nothing && haskey(extensions, pkg.name) && uuid !== nothing && uuid5(UUID(uuid), pkg.name) == pkg.uuid
868-
p = normpath(dirname(locate_package(PkgId(UUID(uuid), name))), "..")
868+
parent_path = locate_package(PkgId(UUID(uuid), name))
869+
if parent_path === nothing
870+
error("failed to find source of parent package: \"$name\"")
871+
end
872+
p = normpath(dirname(parent_path), "..")
869873
extfiledir = joinpath(p, "ext", pkg.name, pkg.name * ".jl")
870874
isfile(extfiledir) && return extfiledir
871875
return joinpath(p, "ext", pkg.name * ".jl")
@@ -1138,10 +1142,10 @@ function insert_extension_triggers(env::String, pkg::PkgId)::Union{Nothing,Missi
11381142
dep_name in weakdeps || continue
11391143
entries::Vector{Any}
11401144
if length(entries) != 1
1141-
error("expected a single entry for $(repr(name)) in $(repr(project_file))")
1145+
error("expected a single entry for $(repr(dep_name)) in $(repr(project_file))")
11421146
end
11431147
entry = first(entries)::Dict{String, Any}
1144-
uuid = get(entry, "uuid", nothing)::Union{String, Nothing}
1148+
uuid = entry["uuid"]::String
11451149
d_weakdeps[dep_name] = uuid
11461150
end
11471151
@assert length(d_weakdeps) == length(weakdeps)
@@ -1247,7 +1251,7 @@ function _tryrequire_from_serialized(modkey::PkgId, build_id::UInt128)
12471251
loading = get(package_locks, modkey, false)
12481252
if loading !== false
12491253
# load already in progress for this module
1250-
loaded = wait(loading)
1254+
loaded = wait(loading::Threads.Condition)
12511255
else
12521256
package_locks[modkey] = Threads.Condition(require_lock)
12531257
try
@@ -1282,7 +1286,7 @@ function _tryrequire_from_serialized(modkey::PkgId, path::String, ocachepath::Un
12821286
loading = get(package_locks, modkey, false)
12831287
if loading !== false
12841288
# load already in progress for this module
1285-
loaded = wait(loading)
1289+
loaded = wait(loading::Threads.Condition)
12861290
else
12871291
for i in 1:length(depmods)
12881292
dep = depmods[i]
@@ -1324,7 +1328,7 @@ function _tryrequire_from_serialized(pkg::PkgId, path::String, ocachepath::Union
13241328
pkgimage = !isempty(clone_targets)
13251329
if pkgimage
13261330
ocachepath !== nothing || return ArgumentError("Expected ocachepath to be provided")
1327-
isfile(ocachepath) || return ArgumentError("Ocachepath $ocachpath is not a file.")
1331+
isfile(ocachepath) || return ArgumentError("Ocachepath $ocachepath is not a file.")
13281332
ocachepath == ocachefile_from_cachefile(path) || return ArgumentError("$ocachepath is not the expected ocachefile")
13291333
# TODO: Check for valid clone_targets?
13301334
isvalid_pkgimage_crc(io, ocachepath) || return ArgumentError("Invalid checksum in cache file $ocachepath.")
@@ -1404,13 +1408,13 @@ end
14041408
staledeps = true
14051409
break
14061410
end
1407-
staledeps[i] = dep
1411+
(staledeps::Vector{Any})[i] = dep
14081412
end
14091413
if staledeps === true
14101414
ocachefile = nothing
14111415
continue
14121416
end
1413-
restored = _include_from_serialized(pkg, path_to_try, ocachefile, staledeps)
1417+
restored = _include_from_serialized(pkg, path_to_try, ocachefile::String, staledeps::Vector{Any})
14141418
if !isa(restored, Module)
14151419
@debug "Deserialization checks failed while attempting to load cache from $path_to_try" exception=restored
14161420
else
@@ -1667,7 +1671,7 @@ function _require(pkg::PkgId, env=nothing)
16671671
loading = get(package_locks, pkg, false)
16681672
if loading !== false
16691673
# load already in progress for this module
1670-
return wait(loading)
1674+
return wait(loading::Threads.Condition)
16711675
end
16721676
package_locks[pkg] = Threads.Condition(require_lock)
16731677

@@ -2160,12 +2164,12 @@ function compilecache(pkg::PkgId, path::String, internal_stderr::IO = stderr, in
21602164
rename(tmppath_so, ocachefile::String; force=true)
21612165
catch e
21622166
e isa IOError || rethrow()
2163-
isfile(ocachefile) || rethrow()
2167+
isfile(ocachefile::String) || rethrow()
21642168
# Windows prevents renaming a file that is in use so if there is a Julia session started
21652169
# with a package image loaded, we cannot rename that file.
21662170
# The code belows append a `_i` to the name of the cache file where `i` is the smallest number such that
21672171
# that cache file does not exist.
2168-
ocachename, ocacheext = splitext(ocachefile)
2172+
ocachename, ocacheext = splitext(ocachefile::String)
21692173
old_cachefiles = Set(readdir(cachepath))
21702174
num = 1
21712175
while true
@@ -2185,7 +2189,7 @@ function compilecache(pkg::PkgId, path::String, internal_stderr::IO = stderr, in
21852189
finally
21862190
rm(tmppath, force=true)
21872191
if cache_objects
2188-
rm(tmppath_o, force=true)
2192+
rm(tmppath_o::String, force=true)
21892193
rm(tmppath_so, force=true)
21902194
end
21912195
end

stdlib/Artifacts/src/Artifacts.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function artifacts_dirs(args...)
5252
return String[abspath(depot, "artifacts", args...) for depot in Base.DEPOT_PATH]
5353
else
5454
# If we've been given an override, use _only_ that directory.
55-
return String[abspath(ARTIFACTS_DIR_OVERRIDE[], args...)]
55+
return String[abspath(ARTIFACTS_DIR_OVERRIDE[]::String, args...)]
5656
end
5757
end
5858

stdlib/FileWatching/src/FileWatching.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ mutable struct _FDWatcher
215215
t.refcount = (0, 0)
216216
t.active = (false, false)
217217
@static if Sys.isunix()
218-
if FDWatchers[t.fdnum] == t
218+
if FDWatchers[t.fdnum] === t
219219
FDWatchers[t.fdnum] = nothing
220220
end
221221
end

stdlib/LibGit2/src/LibGit2.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ function rebase!(repo::GitRepo, upstream::AbstractString="", newbase::AbstractSt
848848
end
849849
finally
850850
if !isempty(newbase)
851-
close(onto_ann)
851+
close(onto_ann::GitAnnotated)
852852
end
853853
close(upst_ann)
854854
close(head_ann)

stdlib/LibGit2/src/callbacks.jl

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -276,18 +276,20 @@ function credentials_callback(libgit2credptr::Ptr{Ptr{Cvoid}}, url_ptr::Cstring,
276276
# information cached inside the payload.
277277
if isempty(p.url)
278278
p.url = unsafe_string(url_ptr)
279-
m = match(URL_REGEX, p.url)
279+
m = match(URL_REGEX, p.url)::RegexMatch
280280

281281
p.scheme = something(m[:scheme], SubString(""))
282282
p.username = something(m[:user], SubString(""))
283-
p.host = m[:host]
283+
p.host = something(m[:host])
284284

285285
# When an explicit credential is supplied we will make sure to use the given
286286
# credential during the first callback by modifying the allowed types. The
287287
# modification only is in effect for the first callback since `allowed_types` cannot
288288
# be mutated.
289-
if p.explicit !== nothing
290-
cred = p.explicit
289+
cache = p.cache
290+
explicit = p.explicit
291+
if explicit !== nothing
292+
cred = explicit
291293

292294
# Copy explicit credentials to avoid mutating approved credentials.
293295
# invalidation fix from cred being non-inferrable
@@ -300,16 +302,15 @@ function credentials_callback(libgit2credptr::Ptr{Ptr{Cvoid}}, url_ptr::Cstring,
300302
else
301303
allowed_types &= Cuint(0) # Unhandled credential type
302304
end
303-
elseif p.cache !== nothing
305+
elseif cache !== nothing
304306
cred_id = credential_identifier(p.scheme, p.host)
305307

306308
# Perform a deepcopy as we do not want to mutate approved cached credentials
307-
if haskey(p.cache, cred_id)
308-
# invalidation fix from p.cache[cred_id] being non-inferrable
309-
p.credential = Base.invokelatest(deepcopy, p.cache[cred_id])
309+
if haskey(cache, cred_id)
310+
# invalidation fix from cache[cred_id] being non-inferrable
311+
p.credential = Base.invokelatest(deepcopy, cache[cred_id])
310312
end
311313
end
312-
313314
p.first_pass = true
314315
else
315316
p.first_pass = false
@@ -447,7 +448,7 @@ function ssh_knownhost_check(
447448
)
448449
if (m = match(r"^(.+):(\d+)$", host)) !== nothing
449450
host = m.captures[1]
450-
port = parse(Int, m.captures[2])
451+
port = parse(Int, something(m.captures[2]))
451452
else
452453
port = 22 # default SSH port
453454
end

stdlib/LibGit2/src/gitcredential.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ function Base.shred!(cred::GitCredential)
4646
cred.host = nothing
4747
cred.path = nothing
4848
cred.username = nothing
49-
cred.password !== nothing && Base.shred!(cred.password)
49+
pwd = cred.password
50+
pwd !== nothing && Base.shred!(pwd)
5051
cred.password = nothing
5152
return cred
5253
end
@@ -122,7 +123,7 @@ function Base.read!(io::IO, cred::GitCredential)
122123
if key == "url"
123124
# Any components which are missing from the URL will be set to empty
124125
# https://git-scm.com/docs/git-credential#git-credential-codeurlcode
125-
Base.shred!(parse(GitCredential, value)) do urlcred
126+
Base.shred!(parse(GitCredential, value::AbstractString)) do urlcred
126127
copy!(cred, urlcred)
127128
end
128129
elseif key in GIT_CRED_ATTRIBUTES

stdlib/LibGit2/src/types.jl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,7 +1389,8 @@ CredentialPayload(p::CredentialPayload) = p
13891389
function Base.shred!(p::CredentialPayload)
13901390
# Note: Avoid shredding the `explicit` or `cache` fields as these are just references
13911391
# and it is not our responsibility to shred them.
1392-
p.credential !== nothing && Base.shred!(p.credential)
1392+
credential = p.credential
1393+
credential !== nothing && Base.shred!(credential)
13931394
p.credential = nothing
13941395
end
13951396

@@ -1430,8 +1431,9 @@ function approve(p::CredentialPayload; shred::Bool=true)
14301431

14311432
# Each `approve` call needs to avoid shredding the passed in credential as we need
14321433
# the credential information intact for subsequent approve calls.
1433-
if p.cache !== nothing
1434-
approve(p.cache, cred, p.url)
1434+
cache = p.cache
1435+
if cache !== nothing
1436+
approve(cache, cred, p.url)
14351437
shred = false # Avoid wiping `cred` as this would also wipe the cached copy
14361438
end
14371439
if p.allow_git_helpers
@@ -1460,8 +1462,9 @@ function reject(p::CredentialPayload; shred::Bool=true)
14601462

14611463
# Note: each `reject` call needs to avoid shredding the passed in credential as we need
14621464
# the credential information intact for subsequent reject calls.
1463-
if p.cache !== nothing
1464-
reject(p.cache, cred, p.url)
1465+
cache = p.cache
1466+
if cache !== nothing
1467+
reject(cache, cred, p.url)
14651468
end
14661469
if p.allow_git_helpers
14671470
reject(p.config, cred, p.url)

stdlib/LibGit2/src/utils.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ end
171171

172172
function credential_identifier(url::AbstractString)
173173
m = match(URL_REGEX, url)
174-
scheme = something(m[:scheme], "")
175-
host = m[:host]
174+
scheme = something(m[:scheme], SubString(""))
175+
host = something(m[:host])
176176
credential_identifier(scheme, host)
177177
end

0 commit comments

Comments
 (0)