Skip to content

Commit 5e56f0a

Browse files
authored
fixes #24378; supportsCopyMem can fail from macro context with tuples (#24383)
fixes #24378 ```nim type Win = typeof(`body`) doAssert not supportsCopyMem((int, Win)) ``` `semAfterMacroCall` doesn't skip the children aliases types in the tuple typedesc construction while the normal program seem to skip the aliases types somewhere `(int, Win)` is kept as `(int, alias string)` instead of expected `(int, string)`
1 parent 74df699 commit 5e56f0a

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

compiler/ast.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1645,7 +1645,7 @@ proc propagateToOwner*(owner, elem: PType; propagateHasAsgn = true) =
16451645
if mask != {} and propagateHasAsgn:
16461646
let o2 = owner.skipTypes({tyGenericInst, tyAlias, tySink})
16471647
if o2.kind in {tyTuple, tyObject, tyArray,
1648-
tySequence, tySet, tyDistinct}:
1648+
tySequence, tyString, tySet, tyDistinct}:
16491649
o2.flags.incl mask
16501650
owner.flags.incl mask
16511651

tests/metatype/ttypetraits.nim

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
discard """
2+
joinable: false
3+
"""
4+
15
import typetraits
26
import macros
37

@@ -402,3 +406,26 @@ when true: # Odd bug where alias can seep inside of `distinctBase`
402406
proc `$`*[T: AdtChild](adtChild: T): string = ""
403407

404408
check 10 is int
409+
410+
411+
block: # bug #24378
412+
macro forked(body: typed): untyped = # typed or untyped does not matter
413+
result = quote do:
414+
type Win = typeof(`body`)
415+
doAssert not supportsCopyMem((int, Win))
416+
doAssert not supportsCopyMem(tuple[a: int, b: Win])
417+
418+
type Win2[T] = typeof(`body`)
419+
doAssert not supportsCopyMem((int, Win2[int]))
420+
doAssert not supportsCopyMem(tuple[a: int, b: Win2[int]])
421+
forked:
422+
"foobar"
423+
424+
425+
type Win111 = typeof("foobar")
426+
doAssert not supportsCopyMem((int, Win111))
427+
doAssert not supportsCopyMem(tuple[a: int, b: Win111])
428+
429+
type Win222[T] = typeof("foobar")
430+
doAssert not supportsCopyMem((int, Win222[int]))
431+
doAssert not supportsCopyMem(tuple[a: int, b: Win222[int]])

0 commit comments

Comments
 (0)