Skip to content

Commit

Permalink
fix #17076 (#17081)
Browse files Browse the repository at this point in the history
  • Loading branch information
ringabout authored Feb 18, 2021
1 parent 4c56873 commit 8873ec6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
6 changes: 5 additions & 1 deletion compiler/jsgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2180,7 +2180,11 @@ proc genSetConstr(p: PProc, n: PNode, r: var TCompRes) =
if it.kind == nkRange:
gen(p, it[0], a)
gen(p, it[1], b)
r.res.addf("[$1, $2]", [a.res, b.res])

if it[0].typ.kind == tyBool:
r.res.addf("$1, $2", [a.res, b.res])
else:
r.res.addf("[$1, $2]", [a.res, b.res])
else:
gen(p, it, a)
r.res.add(a.res)
Expand Down
28 changes: 25 additions & 3 deletions tests/sets/tsets_various.nim
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
discard """
targets: "c cpp js"
output: '''
set is empty
'''
"""


import sets, hashes
import std/[sets, hashes]

from sequtils import toSeq
from algorithm import sorted
from std/sequtils import toSeq
from std/algorithm import sorted

proc sortedPairs[T](t: T): auto = toSeq(t.pairs).sorted
template sortedItems(t: untyped): untyped = sorted(toSeq(t))
Expand Down Expand Up @@ -254,3 +255,24 @@ block: # test correctness after a number of inserts/deletes

testDel(): (var t: HashSet[int])
testDel(): (var t: OrderedSet[int])


template main() =
block:
let a = {true, false}
doAssert $a == "{false, true}"
doAssert a.len == 2

block:
let a = {false .. true}
doAssert $a == "{false, true}"
doAssert a.len == 2

block:
let a = {false .. false}
doAssert $a == "{false}"
doAssert a.len == 1


static: main()
main()

0 comments on commit 8873ec6

Please sign in to comment.