This commit is contained in:
cooldome 2020-09-16 20:37:23 +01:00 • committed by GitHub
commit d938c6411e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 71 additions and 55 deletions

View file

@ -2055,13 +2055,21 @@ proc semGenericConstraints(c: PContext, x: PType): PType =
result = newTypeWithSons(c, tyGenericParam, @[x]) result = newTypeWithSons(c, tyGenericParam, @[x])
proc semGenericParamList(c: PContext, n: PNode, father: PType = nil): PNode = proc semGenericParamList(c: PContext, n: PNode, father: PType = nil): PNode =
template addSym(result: PNode, s: PSym): untyped =
if father != nil: addSonSkipIntLit(father, s.typ)
if sfGenSym notin s.flags: addDecl(c, s)
result.add newSymNode(s)
result = copyNode(n) result = copyNode(n)
if n.kind != nkGenericParams: if n.kind != nkGenericParams:
illFormedAst(n, c.config) illFormedAst(n, c.config)
return return
for i in 0..<n.len: for i in 0..<n.len:
var a = n[i] var a = n[i]
if a.kind != nkIdentDefs: illFormedAst(n, c.config) case a.kind
of nkSym: result.addSym(a.sym)
of nkIdentDefs:
var def = a[^1] var def = a[^1]
let constraint = a[^2] let constraint = a[^2]
var typ: PType var typ: PType
@ -2120,7 +2128,7 @@ proc semGenericParamList(c: PContext, n: PNode, father: PType = nil): PNode =
if covarianceFlag != tfUnresolved: s.typ.flags.incl(covarianceFlag) if covarianceFlag != tfUnresolved: s.typ.flags.incl(covarianceFlag)
if def.kind != nkEmpty: s.ast = def if def.kind != nkEmpty: s.ast = def
if father != nil: addSonSkipIntLit(father, s.typ)
s.position = result.len s.position = result.len
result.add newSymNode(s) result.addSym(s)
if sfGenSym notin s.flags: addDecl(c, s) else:
illFormedAst(n, c.config)

View file

@ -26,3 +26,11 @@ const t = mac("HEllo World")
echo s, " ", t echo s, " ", t
#-----------------------------------------------------------------------------
# issue #15326
macro m(n:typed):auto =
result = n
proc f[T](x:T): T {.m.} = x
discard f(3)