Allow pragmas on parameters (#15178)
This commit is contained in:
parent
813f16a2a3
commit
2cea52ee7e
2 changed files with 17 additions and 2 deletions
|
|
@ -1234,7 +1234,7 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode,
|
||||||
if typ == nil:
|
if typ == nil:
|
||||||
typ = def.typ
|
typ = def.typ
|
||||||
if isEmptyContainer(typ):
|
if isEmptyContainer(typ):
|
||||||
localError(c.config, a.info, "cannot infer the type of parameter '" & a[0].ident.s & "'")
|
localError(c.config, a.info, "cannot infer the type of parameter '" & $a[0] & "'")
|
||||||
|
|
||||||
if typ.kind == tyTypeDesc:
|
if typ.kind == tyTypeDesc:
|
||||||
# consider a proc such as:
|
# consider a proc such as:
|
||||||
|
|
@ -1265,7 +1265,7 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode,
|
||||||
continue
|
continue
|
||||||
|
|
||||||
for j in 0..<a.len-2:
|
for j in 0..<a.len-2:
|
||||||
var arg = newSymG(skParam, a[j], c)
|
var arg = newSymG(skParam, if a[j].kind == nkPragmaExpr: a[j][0] else: a[j], c)
|
||||||
if not hasType and not hasDefault and kind notin {skTemplate, skMacro}:
|
if not hasType and not hasDefault and kind notin {skTemplate, skMacro}:
|
||||||
let param = strTableGet(c.signatures, arg.name)
|
let param = strTableGet(c.signatures, arg.name)
|
||||||
if param != nil: typ = param.typ
|
if param != nil: typ = param.typ
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ wth
|
||||||
0
|
0
|
||||||
(total: 6)
|
(total: 6)
|
||||||
S1
|
S1
|
||||||
|
5
|
||||||
'''
|
'''
|
||||||
"""
|
"""
|
||||||
# bug #1915
|
# bug #1915
|
||||||
|
|
@ -321,3 +322,17 @@ block: #Gensymmed sym sharing forward decl
|
||||||
newProc(sym, body = newStmtList()),
|
newProc(sym, body = newStmtList()),
|
||||||
)
|
)
|
||||||
genGenMacro
|
genGenMacro
|
||||||
|
|
||||||
|
# inject pragma on params
|
||||||
|
|
||||||
|
template test(procname, body: untyped): untyped =
|
||||||
|
proc procname(data {.inject.}: var int = 0) =
|
||||||
|
body
|
||||||
|
|
||||||
|
test(hello):
|
||||||
|
echo data
|
||||||
|
data = 3
|
||||||
|
|
||||||
|
var data = 5
|
||||||
|
|
||||||
|
hello(data)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue