mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-07 21:43:33 +00:00
(cherry picked from commit 465815e894)
This commit is contained in:
@@ -427,8 +427,8 @@ proc fillPartialObject(c: PContext; n: PNode; typ: PType) =
|
||||
proc setVarType(c: PContext; v: PSym, typ: PType) =
|
||||
if v.typ != nil and not sameTypeOrNil(v.typ, typ):
|
||||
localError(c.config, v.info, "inconsistent typing for reintroduced symbol '" &
|
||||
v.name.s & "': previous type was: " & typeToString(v.typ) &
|
||||
"; new type is: " & typeToString(typ))
|
||||
v.name.s & "': previous type was: " & typeToString(v.typ, preferDesc) &
|
||||
"; new type is: " & typeToString(typ, preferDesc))
|
||||
v.typ = typ
|
||||
|
||||
proc semVarOrLet(c: PContext, n: PNode, symkind: TSymKind): PNode =
|
||||
|
||||
@@ -60,3 +60,24 @@ template create(typ: typeDesc, arg: untyped): untyped = `init typ`(arg)
|
||||
var ff = Foo.create(12)
|
||||
|
||||
echo ff.arg
|
||||
|
||||
|
||||
import macros
|
||||
|
||||
# bug #11494
|
||||
macro staticForEach(arr: untyped, body: untyped): untyped =
|
||||
result = newNimNode(nnkStmtList)
|
||||
arr.expectKind(nnkBracket)
|
||||
for n in arr:
|
||||
let b = copyNimTree(body)
|
||||
result.add quote do:
|
||||
block:
|
||||
type it {.inject.} = `n`
|
||||
`b`
|
||||
|
||||
template forEveryMatchingEntity*() =
|
||||
staticForEach([int, string, float]):
|
||||
var a {.inject.}: it
|
||||
echo a
|
||||
|
||||
forEveryMatchingEntity()
|
||||
|
||||
Reference in New Issue
Block a user