Nim icon indicating copy to clipboard operation
Nim copied to clipboard

passing 2 `set`s with 2 different ranges to a proc is not consistent

Open hamidb80 opened this issue 3 years ago • 2 comments

playground

Example

proc `==`[T](a, b: set[T]): bool =
  debugEcho (a.card, b.card)
  debugEcho (a, b)
  debugEcho "---" # <----- uncomment

  if a.card == b.card:
    for i in a:
      if i notin b:
        return false

    true

  else: false


when isMainModule:
  let
    s1: set['a' .. 'g'] = {'a', 'e'}
    # s2: set['a' .. 'g'] = {'b', 'c', 'd', 'f'} # this works fine
    s2 = {'b', 'c', 'd', 'f'}

  echo s1 == s2

Current Output

when line debugEcho "---" is not commented:

(2, 3)
({'a', 'e'}, {'f', 'g'})
---
false

when that line is commented:

(2, 2)
({'a', 'e'}, {'f'})
false

Additional Information

Nim Compiler Version 1.6.6 [Windows: amd64]
Compiled at 2022-05-05
Copyright (c) 2006-2021 by Andreas Rumpf

active boot switches: -d:release

hamidb80 avatar Aug 03 '22 08:08 hamidb80

Some related issues and prs:

https://github.com/nim-lang/Nim/issues/16270 https://github.com/nim-lang/Nim/pull/18388 https://github.com/nim-lang/Nim/issues/18396

ringabout avatar Aug 03 '22 12:08 ringabout