potential fix for semgeneric formal params (#17494)

marked locations where analysis of return formal param is done prior to
args. This might fix some subtle bugs.
This commit is contained in:
Saem Ghani
2021-03-24 03:55:58 -07:00
committed by GitHub
parent 1590d14575
commit 7366a3da37
3 changed files with 8 additions and 2 deletions

View File

@@ -85,6 +85,9 @@ proc checkIsolate*(n: PNode): bool =
of nkCharLit..nkNilLit:
result = true
of nkCallKinds:
# XXX: as long as we don't update the analysis while examining arguments
# we can do an early check of the return type, otherwise this is a
# bug and needs to be moved below
if n[0].typ.flags * {tfGcSafe, tfNoSideEffect} == {}:
return false
for i in 1..<n.len:

View File

@@ -107,6 +107,7 @@ proc computeDeps(cache: IdentCache; n: PNode, declares, uses: var IntSet; topLev
for i in 0..<n.safeLen: deps(n[i])
of nkMixinStmt, nkBindStmt: discard
else:
# XXX: for callables, this technically adds the return type dep before args
for i in 0..<n.safeLen: deps(n[i])
proc hasIncludes(n:PNode): bool =

View File

@@ -452,8 +452,6 @@ proc semGenericStmt(c: PContext, n: PNode,
discard
of nkFormalParams:
checkMinSonsLen(n, 1, c.config)
if n[0].kind != nkEmpty:
n[0] = semGenericStmt(c, n[0], flags+{withinTypeDesc}, ctx)
for i in 1..<n.len:
var a = n[i]
if (a.kind != nkIdentDefs): illFormedAst(a, c.config)
@@ -462,6 +460,10 @@ proc semGenericStmt(c: PContext, n: PNode,
a[^1] = semGenericStmt(c, a[^1], flags, ctx)
for j in 0..<a.len-2:
addTempDecl(c, getIdentNode(c, a[j]), skParam)
# XXX: last change was moving this down here, search for "1.." to keep
# going from this file onward
if n[0].kind != nkEmpty:
n[0] = semGenericStmt(c, n[0], flags+{withinTypeDesc}, ctx)
of nkProcDef, nkMethodDef, nkConverterDef, nkMacroDef, nkTemplateDef,
nkFuncDef, nkIteratorDef, nkLambdaKinds:
checkSonsLen(n, bodyPos + 1, c.config)