Skip to content

Commit f2d1744

Browse files
author
KristofferC
committed
warn if an already loaded package is attempted to be loaded from a different path
1 parent df81bf9 commit f2d1744

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

base/loading.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,6 +1078,7 @@ const pkgorigins = Dict{PkgId,PkgOrigin}()
10781078

10791079
require(uuidkey::PkgId) = @lock require_lock _require_prelocked(uuidkey)
10801080

1081+
const already_warned_path_change_pkgs = Set{String}()
10811082
function _require_prelocked(uuidkey::PkgId)
10821083
just_loaded_pkg = false
10831084
if !root_module_exists(uuidkey)
@@ -1093,6 +1094,15 @@ function _require_prelocked(uuidkey::PkgId)
10931094
error("package `$(uuidkey.name)` did not define the expected \
10941095
module `$(uuidkey.name)`, check for typos in package module name")
10951096
end
1097+
pkgorig = get(pkgorigins, uuidkey, nothing)
1098+
new_path = locate_package(uuidkey)
1099+
if pkgorig.path !== nothing && !samefile(pkgorig.path, new_path) && uuidkey.name already_warned_path_change_pkgs
1100+
@warn "Package $(uuidkey.name) already loaded from path $(repr(pkgorig.path)), \
1101+
now attempted to be loaded from $(repr(new_path)). This might indicate a \
1102+
change of environment between package loads and can mean that incompatible \
1103+
packages have been loaded."
1104+
push!(already_warned_path_change_pkgs, uuidkey.name)
1105+
end
10961106
return root_module(uuidkey)
10971107
end
10981108

0 commit comments

Comments
 (0)