check the owners of generic instantiations properly and fix tinvalidclosure

This commit is contained in:
Zahary Karadjov
2013-08-14 22:20:20 +03:00
parent b01d9b6181
commit 4980ef85e2
2 changed files with 12 additions and 3 deletions

View File

@@ -792,6 +792,7 @@ const
nkStrKinds* = {nkStrLit..nkTripleStrLit}
skLocalVars* = {skVar, skLet, skForVar, skParam, skResult}
skProcKinds* = {skProc, skTemplate, skMacro, skIterator, skMethod, skConverter}
lfFullExternalName* = lfParamCopy # \
# only used when 'gCmd == cmdPretty': Indicates that the symbol has been
@@ -1358,11 +1359,19 @@ proc getStrOrChar*(a: PNode): string =
proc isGenericRoutine*(s: PSym): bool =
case s.kind
of skProc, skTemplate, skMacro, skIterator, skMethod, skConverter:
of skProcKinds:
result = sfFromGeneric in s.flags or
(s.ast != nil and s.ast[genericParamsPos].kind != nkEmpty)
else: nil
proc skipGenericOwner*(s: PSym): PSym =
InternalAssert s.kind in skProcKinds
## Generic instantiations are owned by their originating generic
## symbol. This proc skips such owners and goes straigh to the owner
## of the generic itself (the module or the enclosing proc).
result = if sfFromGeneric in s.flags: s.owner.owner
else: s.owner
proc isRoutine*(s: PSym): bool {.inline.} =
result = s.kind in {skProc, skTemplate, skMacro, skIterator, skMethod,
skConverter}

View File

@@ -219,8 +219,8 @@ proc getHiddenParam(routine: PSym): PSym =
result = hidden.sym
proc isInnerProc(s, outerProc: PSym): bool {.inline.} =
result = s.kind in {skProc, skMethod, skConverter} and
s.owner == outerProc
result = s.kind in {skProc, skMethod, skConverter} and
s.skipGenericOwner == outerProc
#s.typ.callConv == ccClosure
proc addClosureParam(i: PInnerContext, e: PEnv) =