-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Objects casting and custom destructor #24013
Comments
That's just how it works, no bug here. |
The issue is not with the basic concept of how destructors work or type conversions, but rather with how the compiler handles the implicit creation of destructors when casting between related types. The fact that an implicit destructor interferes with an explicit destructor definition without a clear message suggests there might be room for improvement in how this is handled. Even if this behavior is technically correct according to the current Nim specification, it can lead to confusion for developers, especially when dealing with complex inheritance structures. If this is intended behavior, clarifying it in the documentation could help prevent misunderstandings in the future. If it’s not intended, then addressing it could improve the developer experience. I’m not claiming that it’s definitively a bug, but I believe it warrants further discussion to see if this behavior could be made more intuitive or better communicated. |
There is no need to discuss it, in Nim v3 this restriction will be gone. |
Description
An error occurs when defining a custom destructor (
=destroy
) for aChild
object type after calling a parent procedure using type conversion fromChild
toParent
. Specifically, the compiler throws an error:Here is the code that produces the error:
Nim Version
2.1.0
2.0.8
1.6.20
Current Output
Expected Output
Possible Solution
If the
=destroy
procedure is defined before thechildCallParent
procedure (and the type conversion), the program compiles and runs correctly. Uncommenting the first=destroy
proc and removing the second one resolves the issue.However, this workaround is not ideal because it imposes restrictions on the order of procedure definitions.
Additional Information
No response
The text was updated successfully, but these errors were encountered: