dgkf / R

An experimental reimagining of R
https://dgkf.github.io/R
GNU General Public License v3.0
136 stars 5 forks source link

Bug when function is passed an expression that contains an assignment #141

Closed sebffischer closed 4 months ago

sebffischer commented 4 months ago
> f = fn(x) x
> z = f({y = 2})
[1] 2
> z # The result  of {y = 2} is not bound to z
Error: object 'z' not found
backtrace:
> y # but the binding for y is created
[1] 2
sebffischer commented 4 months ago

This is related to the curly braces, because the same code with ( instead of { runs

dgkf commented 4 months ago

Poking at this I found another odd one that may be related.

f <- function(a, b) (a, b)
f({ x <- 1 }, { y <- 2 })
#> [[1]]
#> a @ <environment 0x14d1a4>
#> 
#> [[2]]
#> a @ <environment 0x14d1a4>

I’m guessing that something broke when the branches were added to support tail calls, meaning that expression results only resolve when they absolutely have to. Probably an overlooked code path.