mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-07 05:23:20 +00:00
fixes #20435
---------
Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
Co-authored-by: Jake Leahy <jake@leahy.dev>
Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
(cherry picked from commit 0c179db657)
This commit is contained in:
@@ -187,6 +187,18 @@ proc addTempDecl(c: PContext; n: PNode; kind: TSymKind) =
|
||||
styleCheckDef(c, n.info, s, kind)
|
||||
onDef(n.info, s)
|
||||
|
||||
proc addTempDeclToIdents(c: PContext; n: PNode; kind: TSymKind; inCall: bool) =
|
||||
case n.kind
|
||||
of nkIdent:
|
||||
if inCall:
|
||||
addTempDecl(c, n, kind)
|
||||
of nkCallKinds:
|
||||
for s in n:
|
||||
addTempDeclToIdents(c, s, kind, true)
|
||||
else:
|
||||
for s in n:
|
||||
addTempDeclToIdents(c, s, kind, inCall)
|
||||
|
||||
proc semGenericStmt(c: PContext, n: PNode,
|
||||
flags: TSemGenericFlags, ctx: var GenericCtx): PNode =
|
||||
result = n
|
||||
@@ -359,7 +371,9 @@ proc semGenericStmt(c: PContext, n: PNode,
|
||||
var a = n[i]
|
||||
checkMinSonsLen(a, 1, c.config)
|
||||
for j in 0..<a.len-1:
|
||||
a[j] = semGenericStmt(c, a[j], flags, ctx)
|
||||
a[j] = semGenericStmt(c, a[j], flags+{withinMixin}, ctx)
|
||||
addTempDeclToIdents(c, a[j], skVar, false)
|
||||
|
||||
a[^1] = semGenericStmtScope(c, a[^1], flags, ctx)
|
||||
closeScope(c)
|
||||
of nkForStmt, nkParForStmt:
|
||||
|
||||
30
tests/macros/t20435.nim
Normal file
30
tests/macros/t20435.nim
Normal file
@@ -0,0 +1,30 @@
|
||||
|
||||
#[
|
||||
A better test requires matching, so the use of @ working can be showcased
|
||||
For example:
|
||||
|
||||
proc regularCase[T]() =
|
||||
case [(1, 3), (3, 4)]:
|
||||
of [(1, @a), (_, @b)]:
|
||||
echo a, b
|
||||
else: discard
|
||||
]#
|
||||
|
||||
{.experimental: "caseStmtMacros".}
|
||||
|
||||
import macros
|
||||
|
||||
type Foo = object
|
||||
|
||||
macro `case`(obj: Foo) = quote do: discard
|
||||
|
||||
proc notGeneric() =
|
||||
case Foo()
|
||||
of a b c d: discard
|
||||
|
||||
proc generic[T]() =
|
||||
case Foo()
|
||||
of a b c d: discard
|
||||
|
||||
notGeneric()
|
||||
generic[int]()
|
||||
Reference in New Issue
Block a user