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

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

Open
beef331 opened this issue Mar 12, 2024 · 1 comment
Open

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

beef331 opened this issue Mar 12, 2024 · 1 comment

Comments

@beef331
Copy link
Collaborator

beef331 commented Mar 12, 2024

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()
@arkanoid87
Copy link
Contributor

also happens when T is a distinct object

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

2 participants