nimble-dev / nimble

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

improper error trapping in `sizeReturn` #1364

Closed paciorek closed 11 months ago

paciorek commented 11 months ago

Issue #1354 revealed the following as a problem with error trapping:

> nestedNim2 <- nimbleFunction(
  run = function(){
    returnType(double(0))
    return(nimGarbage())
  }
)
  [Note] For this nimbleFunction to compile, 'nimGarbage' must be defined as a nimbleFunction, nimbleFunctionList, or nimbleList before compilation.
> compileNimble(nestedNim2)
Compiling
  [Note] This may take a minute.
  [Note] Use 'showCompilerOutput = TRUE' to see C++ compilation details.
Error in if (typeEnv$return$type == "nimbleList" || code$args[[1]]$type ==  : 
  missing value where TRUE/FALSE needed

In contrast this is error-trapped, so the issue is with processing return().

> nestedNim2 <- nimbleFunction(
  run = function(){
    returnType(double(0))
    out = nimGarbage()
    return(out)
  }
)

compileNimble(nestedNim2)
  [Note] For this nimbleFunction to compile, 'nimGarbage' must be defined as a nimbleFunction, nimbleFunctionList, or nimbleList before compilation.
Compiling
  [Note] This may take a minute.
  [Note] Use 'showCompilerOutput = TRUE' to see C++ compilation details.
Error: In sizeAssignAfterRecursing: 'nimGarbage' is not available or its output type is unknown.
 This occurred for: out = nimGarbage()
 This was part of the call:  {
  out = nimGarbage()
  return(out)
}
paciorek commented 11 months ago

Note that #1356 also relates to a difference in size processing when inside return versus not.

paciorek commented 11 months ago

I'm adding some error trapping in branch fix_1364.