mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 05:50:30 +00:00
fixes #23422 ref https://github.com/nim-lang/Nim/issues/20997 https://github.com/nim-lang/Nim/pull/21165 The function `cardSet` is used for large sets that are stored in the form of arrays. It shouldn't be passed as a pointer
This commit is contained in:
@@ -2088,7 +2088,7 @@ proc genSetOp(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
|
||||
of mExcl: binaryStmtInExcl(p, e, d, "$1[(NU)($2)>>3] &= ~(1U<<($2&7U));$n")
|
||||
of mCard:
|
||||
var a: TLoc = initLocExpr(p, e[1])
|
||||
putIntoDest(p, d, e, ropecg(p.module, "#cardSet($1, $2)", [addrLoc(p.config, a), size]))
|
||||
putIntoDest(p, d, e, ropecg(p.module, "#cardSet($1, $2)", [rdCharLoc(a), size]))
|
||||
of mLtSet, mLeSet:
|
||||
i = getTemp(p, getSysType(p.module.g.graph, unknownLineInfo, tyInt)) # our counter
|
||||
a = initLocExpr(p, e[1])
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
discard """
|
||||
target: "c cpp"
|
||||
"""
|
||||
|
||||
# Test builtin sets
|
||||
|
||||
# xxx these tests are not very good, this should be revisited.
|
||||
@@ -93,3 +97,37 @@ block:
|
||||
|
||||
doAssert k99 notin s1
|
||||
doAssert k99 notin s2
|
||||
|
||||
block: # bug #23422
|
||||
block:
|
||||
var a: set[uint8] = {1'u8}
|
||||
|
||||
proc printLen(x: set[uint8]): int =
|
||||
doAssert x.len == card(x)
|
||||
result = card(x)
|
||||
|
||||
proc printLenVar(x: var set[uint8]): int =
|
||||
doAssert x.len == card(x)
|
||||
result = card(x)
|
||||
|
||||
doAssert a.len == 1
|
||||
doAssert printLen(a) == 1
|
||||
doAssert printLenVar(a) == card(a)
|
||||
|
||||
block:
|
||||
type Fruit = enum
|
||||
Apple, Banana, Melon
|
||||
|
||||
var a: set[Fruit] = {Apple}
|
||||
|
||||
proc printLen(x: set[Fruit]): int =
|
||||
doAssert x.len == card(x)
|
||||
result = card(x)
|
||||
|
||||
proc printLenVar(x: var set[Fruit]): int =
|
||||
doAssert x.len == card(x)
|
||||
result = card(x)
|
||||
|
||||
doAssert a.len == 1
|
||||
doAssert printLen(a) == 1
|
||||
doAssert printLenVar(a) == card(a)
|
||||
|
||||
Reference in New Issue
Block a user