Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
haoyu234 opened this issue Jun 1, 2024 · 1 comment

Comments

@haoyu234
Copy link
Contributor

haoyu234 commented Jun 1, 2024

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: b172b34
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
Copy link
Member

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]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants