Skip to content

Commit 2bf337a

Browse files
cooldomeAraq
authored andcommitted
fixes #13095 (#13181)
* fixes #13095 * fix typo
1 parent 41cf609 commit 2bf337a

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

compiler/semmagic.nim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ proc evalTypeTrait(c: PContext; traitCall: PNode, operand: PType, context: PSym)
133133
template typeWithSonsResult(kind, sons): PNode =
134134
newTypeWithSons(context, kind, sons).toNode(traitCall.info)
135135

136+
if operand.kind == tyGenericParam or (traitCall.len > 2 and operand2.kind == tyGenericParam):
137+
return traitCall ## tpo early to evaluate
138+
136139
let s = trait.sym.name.s
137140
case s
138141
of "or", "|":

tests/metatype/ttypetraits.nim

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,23 @@ block genericParams:
101101
static: doAssert (int, float).lenTuple == 2
102102
static: doAssert (1, ).lenTuple == 1
103103
static: doAssert ().lenTuple == 0
104+
105+
106+
##############################################
107+
# bug 13095
108+
109+
type
110+
CpuStorage{.shallow.}[T] = ref object
111+
when supportsCopyMem(T):
112+
raw_buffer*: ptr UncheckedArray[T] # 8 bytes
113+
memalloc*: pointer # 8 bytes
114+
isMemOwner*: bool # 1 byte
115+
else: # Tensors of strings, other ref types or non-trivial destructors
116+
raw_buffer*: seq[T] # 8 bytes (16 for seq v2 backed by destructors?)
117+
118+
var x = CpuStorage[string]()
119+
120+
static:
121+
doAssert(not string.supportsCopyMem)
122+
doAssert x.T is string # true
123+
doAssert x.raw_buffer is seq

0 commit comments

Comments
 (0)