diff options
author | Zahary Karadjov <zahary@gmail.com> | 2013-08-14 22:20:20 +0300 |
---|---|---|
committer | Zahary Karadjov <zahary@gmail.com> | 2013-08-19 01:45:16 +0300 |
commit | 4980ef85e254178747dc8ea9fd59b058d33b2df1 (patch) | |
tree | 11ea64d85085a587dc6093b9fba8ac7722a1c165 | |
parent | b01d9b6181be56b1300847cc1352652caa77e437 (diff) | |
download | Nim-4980ef85e254178747dc8ea9fd59b058d33b2df1.tar.gz |
check the owners of generic instantiations properly and fix tinvalidclosure
-rw-r--r-- | compiler/ast.nim | 11 | ||||
-rw-r--r-- | compiler/lambdalifting.nim | 4 |
2 files changed, 12 insertions, 3 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim index 25c66e117..bb015ea27 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -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} diff --git a/compiler/lambdalifting.nim b/compiler/lambdalifting.nim index 9a40b350e..96eb3a5f4 100644 --- a/compiler/lambdalifting.nim +++ b/compiler/lambdalifting.nim @@ -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) = |