Skip to content

Hooks do not work for specific instances of static generic objects #23394

Open
@beef331

Description

@beef331

Description

=copy and =sink cannot use a Uart[Init]. =destroy and =dup use the first Uart[T] defined even if the types do not match.

type
  State = enum
    Uninit
    Init
  Uart[T: static State] = object
    baudRate: int
    port: int

proc `=destroy`(uart: var Uart[Init]) = echo "Destroyed"

# proc `=copy`(a: var Uart[Init], b: Uart[Init]) {.error.} # Error: signature for '=copy' must be proc[T: object](x: var T; y: T)

proc main() =
  var a = Uart[Uninit]()

main()

Nim Version

2.0.2

Current Output

"Destroyed"

Expected Output

No response

Possible Solution

No response

Additional Information

Given the following uses the proper hooks it seems it's related to #22445 where the not using generic parameters results in two types being equivalent even though they certainly are not.

type
  State = enum
    Uninit
    Init
  Uart[T: static State] = object
    baudRate: int
    port: int
    val: typeof(T)

proc `=destroy`(uart: var Uart[Init]) = echo "Destroyed" 
proc `=destroy`(uart: var Uart[Uninit]) = echo "Uninit'd"

proc main() =
  var a = Uart[Uninit]()

main()

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