Skip to content

Broken finializer binding for distinct refs #19138

Open
@alaviss

Description

@alaviss

Example

type
  SocketObj = object

  Socket = ref SocketObj

  AsyncSocketObj = distinct SocketObj

  AsyncSocket = ref AsyncSocketObj

proc `=destroy`(s: var SocketObj) =
  echo "Destroying Socket"

proc `=destroy`(s: var AsyncSocketObj) =
  echo "Destroying AsyncSocket"

proc newSocket(): Socket = Socket()
proc newAsyncSocket(): AsyncSocket = AsyncSocket(newSocket())

proc main() =
  var x = newSocket()
  var y = newAsyncSocket()

  x = nil
  y = nil

  GC_fullCollect()

main()

Current Output

Destroying Socket
Destroying Socket

Expected Output

Destroying Socket
Destroying AsyncSocket

Additional Information

  • Behaves correctly with --gc:arc
  • Found during development of nim-sys
$ nim -v
Nim Compiler Version 1.7.1 [Linux: amd64]
Compiled at 2021-11-08
Copyright (c) 2006-2021 by Andreas Rumpf

git hash: 83a9c3ba31d180cd5e31026d8b7603bf7adea18c
active boot switches: -d:release -d:nimUseLinenoise

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions