Skip to content

Commit

Permalink
Check for sealed namespace in is_installed()
Browse files Browse the repository at this point in the history
Closes #1378
  • Loading branch information
lionel- committed May 24, 2022
1 parent 2b472ff commit 5fcde82
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# rlang (development version)

* `is_installed()` now detects unsealed namespaces (#1378). This fixes
inconsistent behaviour when run within user onLoad hooks.

* Source references in backtraces and `last_error()`/`last_trace()` instructions
are now clickable in IDEs that support links (#1396).

Expand Down
8 changes: 7 additions & 1 deletion R/session.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,13 @@ detect_installed <- function(info) {
}

flatten_lgl(pmap(info, function(pkg, cmp, ver) {
if (requireNamespace(pkg, quietly = TRUE)) {
# Check for sealed namespaces to protect against `is_installed()`
# being called from user hooks of `pkg` (#1378)
is_fully_loaded <-
requireNamespace(pkg, quietly = TRUE) &&
env_is_locked(ns_env(pkg))

if (is_fully_loaded) {
is_na(ver) || exec(cmp, utils::packageVersion(pkg), ver)
} else {
FALSE
Expand Down

0 comments on commit 5fcde82

Please sign in to comment.