Skip to content

Commit

Permalink
fixes #24378; supportsCopyMem can fail from macro context with tuples
Browse files Browse the repository at this point in the history
  • Loading branch information
ringabout committed Oct 29, 2024
1 parent d618974 commit 088f19d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions compiler/semtypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ proc semAnonTuple(c: PContext, n: PNode, prev: PType): PType =
result = newOrPrevType(tyTuple, prev, c)
for it in n:
let t = semTypeNode(c, it, nil)
addSonSkipIntLitChecked(c, result, t, it, c.idgen)
addSonSkipIntLitChecked(c, result, t.skipTypes({tyAlias}), it, c.idgen)

proc firstRange(config: ConfigRef, t: PType): PNode =
if t.skipModifier().kind in tyFloat..tyFloat64:
Expand Down Expand Up @@ -543,7 +543,7 @@ proc semTuple(c: PContext, n: PNode, prev: PType): PType =
fSym.sym.ast = a[^1]
fSym.sym.ast.flags.incl nfSkipFieldChecking
result.n.add fSym
addSonSkipIntLit(result, typ, c.idgen)
addSonSkipIntLit(result, typ.skipTypes({tyAlias}), c.idgen)
styleCheckDef(c, a[j].info, field)
onDef(field.info, field)
if result.n.len == 0: result.n = nil
Expand Down
23 changes: 23 additions & 0 deletions tests/metatype/ttypetraits.nim
Original file line number Diff line number Diff line change
Expand Up @@ -402,3 +402,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]])

0 comments on commit 088f19d

Please sign in to comment.