Closed Ellpeck closed 1 month ago
This also occurs when slicing, see this test:
assertSliced(label('dead code (return in if)', []),
shell, `f <- function(x) {
x <- 3 * x
if(k)
return(x)
else
return(1)
# alles drunter soll natürlich weg
x <- 2
return(x)
}
f(5)`, ['12@f'], `f <- function(x) {
x <- 3 * x
if(k) return(x) else
return(1)
x <- 2
return(x)
}
f(5)`)
This should be fixed by the linked PR, please still include the tests as part of #800.
produces this Mermaid diagram. The assignment of
x <- 2
is still contained in it, even though it should be considered dead code.Dead code detection works correctly, however, when a return always occurs (ie outside of an if/else block), like in this example:
Both of these tests are included in #800.