rco
rco copied to clipboard
Bug: DEE should check if eliminating an undefined variable
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.