Skip to content

Error: type mismatch: got 'proc ()' for 'handleOOM' but expected 'proc (){.nimcall, gcsafe.}' #24781

@forchid

Description

@forchid

Nim Version

Nim Compiler Version 2.2.2 [Windows: amd64]
Compiled at 2025-02-06
Copyright (c) 2006-2025 by Andreas Rumpf

active boot switches: -d:release

Description

According to the nim 2.2.2 stdlib system website example, it can't be compiled. If adding the pragmas {.nimcall, gcsafe.} then re-compiling it, the Error: 'handleOOM' is not GC-safe as it accesses 'gOutOfMem' which is a global using GC'ed memory was thrown.

var gOutOfMem: ref OutOfMemDefect #EOutOfMemory
new(gOutOfMem) # need to be allocated *before* OOM really happened!
gOutOfMem.msg = "out of memory"

proc handleOOM() =
  raise gOutOfMem

system.outOfMemHook = handleOOM

Current Output

>nim c -d:release oomhook
Hint: used config file '..\.choosenim\toolchains\nim-2.2.2\config\nim.cfg' [Conf]
Hint: used config file '..\.choosenim\toolchains\nim-2.2.2\config\config.nims' [Conf]
.......................................................................
..\oomhook.nim(8, 23) Error: type mismatch: got 'proc ()' for 'handleOOM' but expected 'proc (){.nimcall, gcsafe.}'
  Pragma mismatch: got '{..}', but expected '{.gcsafe.}'.

Expected Output

Compiling passes.

Known Workarounds

No response

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions