nimble-dev / nimble

The base NIMBLE package for R
http://R-nimble.org
BSD 3-Clause "New" or "Revised" License
156 stars 23 forks source link

discuss: should missing variables in a nf trigger warning or error? #1365

Closed paciorek closed 9 months ago

paciorek commented 9 months ago

In a case like this, we warn about missing b and C++ compilation fails. It's not clear to me why we don't error trap this in our compilation process. I guess the idea is that we want to allow uncompiled execution with b being found by scoping? I'm not sure that feels compelling to me if that is the reason given we generally want uncompiled and compiled execution to match.

Note that if this were c <- foo(a) with missing foo we do warn about that via a separate mechanism.

As a side note,

test1 <- nimbleFunction(
    run = function() {
        a  <- 7
        c <- a+b  # warning about 'b' not yet created
        return(c)
        returnType(double(0))
    })
compileNimble(test1)

Compiling
  [Note] This may take a minute.
  [Note] Use 'showCompilerOutput = TRUE' to see C++ compilation details.
Error: Failed to create the shared library. Run 'printErrors()' to see the compilation errors.
In addition: Warning message:
variable 'b' has not been created yet. 
paciorek commented 9 months ago

I'm changing this to an error.