You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Destructors of wrong type are injected for phantom types (with generic parameters that don't appear in the type's fields).
Here is a toy example:
typePhantom[T] =object
value: int# markerField: TprocinitPhantom[T](value: int): Phantom[T] =doAssert value >=0echo"created "&$Phantom[T] &" with value "&$value
result=Phantom[T](value: value)
proc`=wasMoved`[T](x: varPhantom[T]) =
x.value =-1proc`=destroy`[T](x: Phantom[T]) =if x.value >=0:
echo"destroyed "&$Phantom[T] &" with value "&$x.value
let
x =initPhantom[float](1)
y =initPhantom[string](2)
z =initPhantom[byte](3)
Nim Version
Nim Compiler Version 2.2.0 [Linux: amd64]
Compiled at 2024-10-02
Copyright (c) 2006-2024 by Andreas Rumpf
git hash: 78983f1876726a49c69d65629ab433ea1310ece1
active boot switches: -d:release
Nim Compiler Version 2.2.1 [Linux: amd64]
Compiled at 2024-10-27
Copyright (c) 2006-2024 by Andreas Rumpf
git hash: 24aa92c14f2301d1ef63f59bc4ae2ec31a64f9c5
active boot switches: -d:release
Current Output
created Phantom[system.float] with value 1
created Phantom[system.string] with value 2
created Phantom[system.byte] with value 3
destroyed Phantom[system.float] with value 3
destroyed Phantom[system.float] with value 2
destroyed Phantom[system.float] with value 1
Expected Output
created Phantom[system.float] with value 1
created Phantom[system.string] with value 2
created Phantom[system.byte] with value 3
destroyed Phantom[system.byte] with value 3
destroyed Phantom[system.string] with value 2
destroyed Phantom[system.float] with value 1
Known Workarounds
The problem disappears if the field markerField: T is uncommented.
Additional Information
No response
The text was updated successfully, but these errors were encountered:
Description
Destructors of wrong type are injected for phantom types (with generic parameters that don't appear in the type's fields).
Here is a toy example:
Nim Version
Current Output
Expected Output
Known Workarounds
The problem disappears if the field
markerField: T
is uncommented.Additional Information
No response
The text was updated successfully, but these errors were encountered: