Fix doubly typed forward declarations (#18279)

* Add testcase

* Fix testcase

* Fix doubly typed forward decls

* Better fix
This commit is contained in:
Clyybber 2021-06-16 16:40:22 +02:00 • committed by GitHub
commit 13b94c0297
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 2 deletions

View file

@ -1890,11 +1890,16 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind,
var (proto, comesFromShadowScope) =
if isAnon: (nil, false)
else: searchForProc(c, declarationScope, s)
if proto == nil and sfForward in s.flags:
if proto == nil and sfForward in s.flags and n[bodyPos].kind != nkEmpty:
## In cases such as a macro generating a proc with a gensymmed name we
## know `searchForProc` will not find it and sfForward will be set. In
## such scenarios the sym is shared between forward declaration and we
## can treat the `s` as the proto.
## To differentiate between that happening and a macro just returning a
## forward declaration that has been typed before we check if the body
## is not empty. This has the sideeffect of allowing multiple forward
## declarations if they share the same sym.
## See the "doubly-typed forward decls" case in tmacros_issues.nim
proto = s
let hasProto = proto != nil