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
Method dispatch silently breaks on non-ref objects #4318
Labels
Comments
This issue has been automatically marked as stale because it has not had recent activity. If you think it is still a valid issue, write a comment below; otherwise it will be closed. Thank you for your contributions. |
Since Nim v 0.19.0, this will give error:
|
ringabout
added a commit
to ringabout/Nim
that referenced
this issue
Nov 10, 2020
narimiran
pushed a commit
that referenced
this issue
Nov 16, 2020
PMunch
pushed a commit
to PMunch/Nim
that referenced
this issue
Jan 6, 2021
* close nim-lang#4318(add testcase for nim-lang#4318) * Update tests/objects/t4318.nim Co-authored-by: Juan Carlos <juancarlospaco@gmail.com> Co-authored-by: Juan Carlos <juancarlospaco@gmail.com>
mildred
pushed a commit
to mildred/Nim
that referenced
this issue
Jan 11, 2021
* close nim-lang#4318(add testcase for nim-lang#4318) * Update tests/objects/t4318.nim Co-authored-by: Juan Carlos <juancarlospaco@gmail.com> Co-authored-by: Juan Carlos <juancarlospaco@gmail.com>
irdassis
pushed a commit
to irdassis/Nim
that referenced
this issue
Mar 16, 2021
* close nim-lang#4318(add testcase for nim-lang#4318) * Update tests/objects/t4318.nim Co-authored-by: Juan Carlos <juancarlospaco@gmail.com> Co-authored-by: Juan Carlos <juancarlospaco@gmail.com>
ardek66
pushed a commit
to ardek66/Nim
that referenced
this issue
Mar 26, 2021
* close nim-lang#4318(add testcase for nim-lang#4318) * Update tests/objects/t4318.nim Co-authored-by: Juan Carlos <juancarlospaco@gmail.com> Co-authored-by: Juan Carlos <juancarlospaco@gmail.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Following is with Nim built from git:07d7d35d995262830
Consider this code:
Observed behavior: This program prints
There are no warnings or errors, even on verbosity:2.
It appears that when I say "var a: A = b" I am implicitly converting b to A type and therefore the b identity is lost. If B has fields, it appears those fields are getting thrown away. There is no text indicating this loss of identity in the manual either under http://nim-lang.org/docs/manual.html#types-tuples-and-object-types or http://nim-lang.org/docs/manual.html#multi-methods (the former section says "the default assignment operator for objects copies each component" but it is far from obvious this text implies "...and subclass-related are thrown away"). The behavior appears to be in active conflict with the "convertible relations" section http://nim-lang.org/docs/manual.html#type-relations-convertible-relation which say A and B should be explicitly convertible because B is a subtype but do not say they are implicitly convertible.
Expected behavior:
B\nB
. However, given how I understand the Nim memory model to work, I expect this is probably not possible for non-ref objects. (C++ for example would not support this for stack objects.)A
andB of A
involves a loss of information or at least a change analogous to copying between ints and floats, therefore copying betweena:A
andb:B
whereA
andB
are non-ref objects should require an explicit cast. Again, this behavior (error on direct assignment fromB of A
toA
without cast) seems to be required by the "convertible relation" section of the manual.l
, etc) Nim should give me a warning for the above code thatmethod
is useless and I should useproc
instead. In general, any pair ofmethod
s could just as well beproc
s unless at least one argument dispatches on a ref object. Any use ofmethod
where the special dispatch capabilities ofmethod
are not being used therefore is probably accidental on the part of the user and a warning is appropriate.The text was updated successfully, but these errors were encountered: