mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-08 14:03:23 +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
(cherry picked from commit 4b6a9e4add)
This commit is contained in:
@@ -2133,7 +2133,7 @@ proc genSetOp(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
|
||||
of mCard:
|
||||
var a: TLoc
|
||||
initLocExpr(p, e[1], a)
|
||||
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:
|
||||
getTemp(p, getSysType(p.module.g.graph, unknownLineInfo, tyInt), i) # our counter
|
||||
initLocExpr(p, e[1], a)
|
||||
|
||||
@@ -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