A closure causes nimscript to fail with unhandled exception #4906

Closed
grokqcd opened this Issue Oct 17, 2016 · 0 comments

Projects

None yet

2 participants

@grokqcd
grokqcd commented Oct 17, 2016

Running the following code under nimscript (code with *.nims) using devel Nim (git hash: 3ba2d0...)

type
  #MyClosureType = proc(x,y:int):int {.closure.}  # same crash if we explicitly use a closure
  MyClosureType = proc(x,y:int):int

proc myTest(x,y:int,foo:MyClosureType):int = return foo(x,y)

# Expect to see "Add: 11"
echo "Add: ", myTest(5,6,proc (a,b:int):int = return a+b)

results in the output

% nim e bug.nims
Hint: used config file '/usr/local/share/nim/devel/nim/config/nim.cfg' [Conf]
Traceback (most recent call last)
nim.nim(115) nim
nim.nim(59) handleCmdLine
scriptconfig.nim(154) runNimScript
passes.nim(198) processModule
passes.nim(131) processTopLevelStmt
vm.nim(1530) myProcess
vm.nim(1487) evalStmt
vm.nim(1454) execute
vm.nim(909) rawExecute
system.nim(2546) sysFatal
Error: unhandled exception: index out of bounds [IndexError]

However, the code works as expected if copied to *.nim and run under nim c -r bug.nim

@Araq Araq added a commit that closed this issue Oct 21, 2016
@Araq Araq fixes #4906 50dc712
@Araq Araq closed this in 50dc712 Oct 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment