Skip to content

Commit 5cdb501

Browse files
KristofferCKristofferC
authored andcommitted
warn if an already loaded package is attempted to be loaded from a different path
1 parent df81bf9 commit 5cdb501

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

base/loading.jl

Lines changed: 11 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{UUID}()
10811082
function _require_prelocked(uuidkey::PkgId)
10821083
just_loaded_pkg = false
10831084
if !root_module_exists(uuidkey)
@@ -1093,6 +1094,16 @@ 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 !== nothing && pkgorig.path !== nothing &&
1100+
!samefile(fixup_stdlib_path(pkgorig.path), new_path) && uuidkey.uuid already_warned_path_change_pkgs
1101+
@warn "Package $(uuidkey.name) already loaded from path $(repr(pkgorig.path)), \
1102+
now attempted to be loaded from $(repr(new_path)). This might indicate a \
1103+
change of environment between package loads and can mean that incompatible \
1104+
packages have been loaded."
1105+
push!(already_warned_path_change_pkgs, uuidkey.uuid)
1106+
end
10961107
return root_module(uuidkey)
10971108
end
10981109

0 commit comments

Comments
 (0)