rco icon indicating copy to clipboard operation
rco copied to clipboard

Bug: DEE should check if eliminating an undefined variable

Open jcrodriguez1989 opened this issue 5 years ago • 0 comments

Dead Expression Elimination is optimizing the code:

code <- paste(
  "foo <- function() {",
  "  undef_var + 3",
  "  rnorm(1)",
  "}",
  "foo()",
  sep = "\n"
)
cat(opt_dead_expr(list(code))$codes[[1]])

to:

foo <- function() {
  rnorm(1)
}
foo()

However, their behavior is not equivalent, in the first definition, if undef_var is not present in the parent env, then it will give an error. DEE should check if expression to eliminate have never-assigned variables.

jcrodriguez1989 avatar Jul 12 '19 19:07 jcrodriguez1989