Skip to content

Circular register_theme_element() bug #6162

Closed
@teunbrand

Description

@teunbrand

Accidentally, I found myself in a situation where I defined a theme element with itself as its parent.
I couldn't reprex this bug because it halts execution of rmarkdown::render(), but here are the steps to reproduce:

library(ggplot2)
register_theme_elements(
  foobar = element_rect(),
  element_tree = list(foobar = el_def("element_rect", inherit = "foobar"))
)
calc_element("foobar", theme_get())
#> Error in match.fun(FUN) : node stack overflow
#> Error during wrapup: node stack overflow
#> Error: no more error handlers available (recursive errors?); invoking 'abort' restart

It is fine when I use inherit = "rect" or something that isn't the name of the element itself.
So it seems like defining an element with itself as its parent causes the bug.

This error was complicated to track down and the error message itself wasn't very helpful.
I propose we add a check to register_theme_elements() that throws an error when trying to define new elements that have themselves as parents.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions