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

Equality is not working if Ref Object defined in a block scope #17965

Closed
al6x opened this issue May 7, 2021 · 2 comments
Closed

Equality is not working if Ref Object defined in a block scope #17965

al6x opened this issue May 7, 2021 · 2 comments

Comments

@al6x
Copy link

al6x commented May 7, 2021

The equality operator == works incorrectly if the ref object is defined inside of a block: scope.

In the example the result of @[a] == @[b] would be false, but if the block scope removed, it will be true.

Example

playground

if is_main_module: # or block:
  type User = ref object
    id: int

  proc `==`(a, b: User): bool = a[] == b[]

  var a = User(id: 1)
  var b = User(id: 1)
  echo a == b       # ==> true
  echo @[a] == @[b] # ==> false - Error!
Nim Compiler Version 1.4.6 [MacOSX: amd64]
Compiled at 2021-05-06
Copyright (c) 2006-2020 by Andreas Rumpf

active boot switches: -d:release```
@al6x al6x changed the title Equality is not working for ref object if it's defined inside of a block scope Equality is not working if Ref Object defined in a block scope May 7, 2021
@timotheecour
Copy link
Member

sounds like duplicate of #13747

ok to close this as duplicate?

@al6x
Copy link
Author

al6x commented May 7, 2021

Sure, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants