From 5e56f0a356bc86fd4b135c170c0fee2e96e7257b Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Thu, 31 Oct 2024 05:58:39 +0800 Subject: [PATCH] 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)` --- compiler/ast.nim | 2 +- tests/metatype/ttypetraits.nim | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/compiler/ast.nim b/compiler/ast.nim index 5ff986776c..2f6c272320 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -1645,7 +1645,7 @@ proc propagateToOwner*(owner, elem: PType; propagateHasAsgn = true) = if mask != {} and propagateHasAsgn: let o2 = owner.skipTypes({tyGenericInst, tyAlias, tySink}) if o2.kind in {tyTuple, tyObject, tyArray, - tySequence, tySet, tyDistinct}: + tySequence, tyString, tySet, tyDistinct}: o2.flags.incl mask owner.flags.incl mask diff --git a/tests/metatype/ttypetraits.nim b/tests/metatype/ttypetraits.nim index 0523390a76..74ace75c3a 100644 --- a/tests/metatype/ttypetraits.nim +++ b/tests/metatype/ttypetraits.nim @@ -1,3 +1,7 @@ +discard """ + joinable: false +""" + import typetraits import macros @@ -402,3 +406,26 @@ when true: # Odd bug where alias can seep inside of `distinctBase` proc `$`*[T: AdtChild](adtChild: T): string = "" check 10 is int + + +block: # bug #24378 + macro forked(body: typed): untyped = # typed or untyped does not matter + result = quote do: + type Win = typeof(`body`) + doAssert not supportsCopyMem((int, Win)) + doAssert not supportsCopyMem(tuple[a: int, b: Win]) + + type Win2[T] = typeof(`body`) + doAssert not supportsCopyMem((int, Win2[int])) + doAssert not supportsCopyMem(tuple[a: int, b: Win2[int]]) + forked: + "foobar" + + + type Win111 = typeof("foobar") + doAssert not supportsCopyMem((int, Win111)) + doAssert not supportsCopyMem(tuple[a: int, b: Win111]) + + type Win222[T] = typeof("foobar") + doAssert not supportsCopyMem((int, Win222[int])) + doAssert not supportsCopyMem(tuple[a: int, b: Win222[int]])