nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.47k stars 1.47k forks source link

Why this code produces a compiler warning: Warning: `=destroy`(t.c) can raise an unlisted exception: Exception #23667

Open haoyu234 opened 3 months ago

haoyu234 commented 3 months ago

Description

https://play.nim-lang.org/#pasty=XdqZmWbb


type
  ChunkBase* {.acyclic.} = object of RootObj
    nextChunk: Chunk

  Chunk* = ref ChunkBase
  ChunkObj2 = object of ChunkBase
  Chunk2 = ref ChunkObj2

  Test = ref TestObj
  TestObj = object
    c: Chunk

proc `=destroy`(chunk: ChunkObj2) = discard

proc newChunk*(): owned Chunk {.inline.} =
  Chunk()

proc `=destroy`(t: TestObj) =
  `=destroy`(t.c)  # Warning: `=destroy`(t.c) can raise an unlisted exception: Exception [Effect]

What should I do to resolve the warning?

Nim Version

Nim Compiler Version 2.1.1 [Linux: amd64] Compiled at 2024-05-30 Copyright (c) 2006-2024 by Andreas Rumpf

git hash: b172b34a245959c7d5e8f4df3c3dcbe88b7ba6fa active boot switches: -d:release

Current Output

Hint: used config file '/playground/nim/config/nim.cfg' [Conf]
Hint: used config file '/playground/nim/config/config.nims' [Conf]
......................................................................
/usercode/in.nim(18, 6) template/generic instantiation from here
/usercode/in.nim(19, 13) Warning: `=destroy`(t.c) can raise an unlisted exception: Exception [Effect]
/usercode/in.nim(7, 3) Hint: 'Chunk2' is declared but not used [XDeclaredButNotUsed]
/usercode/in.nim(9, 3) Hint: 'Test' is declared but not used [XDeclaredButNotUsed]

Expected Output

no warning

Possible Solution

No response

Additional Information

No response

ringabout commented 3 months ago

Slightly simplified

type
  Chunk* = ref object of RootObj
    nextChunk: Chunk

  TestObj = object
    c: Chunk

proc newChunk*(): Chunk =
  Chunk()

proc `=destroy`(t: TestObj) =
  `=destroy`(t.c)  # Warning: `=destroy`(t.c) can raise an unlisted exception: Exception [Effect]