Skip to content

Commit bac8ff0

Browse files
committed
error on circular parents
1 parent b174986 commit bac8ff0

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

R/theme-elements.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,16 @@ register_theme_elements <- function(..., element_tree = NULL, complete = TRUE) {
414414
t <- theme(..., complete = complete)
415415
ggplot_global$theme_default <- ggplot_global$theme_default %+replace% t
416416

417+
# Check element tree, prevent elements from being their own parent (#6162)
418+
bad_parent <- unlist(Map(
419+
function(name, el) any(name %in% el$inherit),
420+
name = names(element_tree), el = element_tree
421+
))
422+
if (any(bad_parent)) {
423+
bad_parent <- names(element_tree)[bad_parent]
424+
cli::cli_abort("Invalid parent: {.and {.val {bad_parent}}}.")
425+
}
426+
417427
# Merge element trees
418428
ggplot_global$element_tree <- defaults(element_tree, ggplot_global$element_tree)
419429

0 commit comments

Comments
 (0)