Open
Description
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()