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
commit 7366a3da37
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 2 deletions

View file

@ -85,6 +85,9 @@ proc checkIsolate*(n: PNode): bool =
of nkCharLit..nkNilLit: of nkCharLit..nkNilLit:
result = true result = true
of nkCallKinds: 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} == {}: if n[0].typ.flags * {tfGcSafe, tfNoSideEffect} == {}:
return false return false
for i in 1..<n.len: 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]) for i in 0..<n.safeLen: deps(n[i])
of nkMixinStmt, nkBindStmt: discard of nkMixinStmt, nkBindStmt: discard
else: else:
# XXX: for callables, this technically adds the return type dep before args
for i in 0..<n.safeLen: deps(n[i]) for i in 0..<n.safeLen: deps(n[i])
proc hasIncludes(n:PNode): bool = proc hasIncludes(n:PNode): bool =

View file

@ -452,8 +452,6 @@ proc semGenericStmt(c: PContext, n: PNode,
discard discard
of nkFormalParams: of nkFormalParams:
checkMinSonsLen(n, 1, c.config) 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: for i in 1..<n.len:
var a = n[i] var a = n[i]
if (a.kind != nkIdentDefs): illFormedAst(a, c.config) 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) a[^1] = semGenericStmt(c, a[^1], flags, ctx)
for j in 0..<a.len-2: for j in 0..<a.len-2:
addTempDecl(c, getIdentNode(c, a[j]), skParam) 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, of nkProcDef, nkMethodDef, nkConverterDef, nkMacroDef, nkTemplateDef,
nkFuncDef, nkIteratorDef, nkLambdaKinds: nkFuncDef, nkIteratorDef, nkLambdaKinds:
checkSonsLen(n, bodyPos + 1, c.config) checkSonsLen(n, bodyPos + 1, c.config)