This commit is contained in:
flywind 2021-02-17 23:59:58 -06:00 • committed by GitHub
commit 8873ec6084
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 4 deletions

View file

@ -2180,6 +2180,10 @@ proc genSetConstr(p: PProc, n: PNode, r: var TCompRes) =
if it.kind == nkRange: if it.kind == nkRange:
gen(p, it[0], a) gen(p, it[0], a)
gen(p, it[1], b) gen(p, it[1], b)
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]) r.res.addf("[$1, $2]", [a.res, b.res])
else: else:
gen(p, it, a) gen(p, it, a)

View file

@ -1,14 +1,15 @@
discard """ discard """
targets: "c cpp js"
output: ''' output: '''
set is empty set is empty
''' '''
""" """
import sets, hashes import std/[sets, hashes]
from sequtils import toSeq from std/sequtils import toSeq
from algorithm import sorted from std/algorithm import sorted
proc sortedPairs[T](t: T): auto = toSeq(t.pairs).sorted proc sortedPairs[T](t: T): auto = toSeq(t.pairs).sorted
template sortedItems(t: untyped): untyped = sorted(toSeq(t)) template sortedItems(t: untyped): untyped = sorted(toSeq(t))
@ -254,3 +255,24 @@ block: # test correctness after a number of inserts/deletes
testDel(): (var t: HashSet[int]) testDel(): (var t: HashSet[int])
testDel(): (var t: OrderedSet[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()