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

=copy and =sink not called in instantiation of forward-declared generic proc #18030

Closed
exelotl opened this issue May 16, 2021 · 0 comments
Closed

Comments

@exelotl
Copy link
Contributor

exelotl commented May 16, 2021

When a generic proc is invoked before its implementation is defined, =copy and =sink will not be called for any assignments that occur within the proc's implementation.

Example

type
  Foo = object
    n: int

proc `=copy`(dst: var Foo, src: Foo) =
  echo "copying"
  dst.n = src.n

proc `=sink`(dst: var Foo, src: Foo) =
  echo "sinking"
  dst.n = src.n

var a: Foo

proc putValue[T](n: T)

proc main =
  putValue(123)

proc putValue[T](n: T) =
  var b = Foo(n:n)
  a = b
  echo b.n

main()

Current Output

123

Expected Output

copying
123

(or, if echo b.n is commented out):

sinking
123

Additional Information

This appears to be a regression that was introduced between Nim 1.0.0 and 1.2.0 (according to the playground).

$ nim -v
Nim Compiler Version 1.5.1 [Linux: amd64]
Compiled at 2021-05-16
@exelotl exelotl changed the title =copy and =sink not called in forward-declared generic instantiation. =copy and =sink not called in instantiation of forward-declared generic proc May 16, 2021
Araq added a commit that referenced this issue Jul 1, 2021
@Araq Araq closed this as completed in 3ceaf5c Jul 1, 2021
PMunch pushed a commit to PMunch/Nim that referenced this issue Mar 28, 2022
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