fixes #2752
This commit is contained in:
parent
f8bababa2a
commit
35f8cc0bdd
3 changed files with 31 additions and 7 deletions
|
|
@ -226,13 +226,14 @@ proc generateInstance(c: PContext, fn: PSym, pt: TIdTable,
|
||||||
# NOTE: for access of private fields within generics from a different module
|
# NOTE: for access of private fields within generics from a different module
|
||||||
# we set the friend module:
|
# we set the friend module:
|
||||||
c.friendModules.add(getModule(fn))
|
c.friendModules.add(getModule(fn))
|
||||||
#let oldScope = c.currentScope
|
let oldScope = c.currentScope
|
||||||
#c.currentScope = fn.scope
|
while not isTopLevel(c): c.currentScope = c.currentScope.parent
|
||||||
result = copySym(fn, false)
|
result = copySym(fn, false)
|
||||||
incl(result.flags, sfFromGeneric)
|
incl(result.flags, sfFromGeneric)
|
||||||
result.owner = fn
|
result.owner = fn
|
||||||
result.ast = n
|
result.ast = n
|
||||||
pushOwner(result)
|
pushOwner(result)
|
||||||
|
|
||||||
openScope(c)
|
openScope(c)
|
||||||
internalAssert n.sons[genericParamsPos].kind != nkEmpty
|
internalAssert n.sons[genericParamsPos].kind != nkEmpty
|
||||||
n.sons[namePos] = newSymNode(result)
|
n.sons[namePos] = newSymNode(result)
|
||||||
|
|
@ -264,7 +265,7 @@ proc generateInstance(c: PContext, fn: PSym, pt: TIdTable,
|
||||||
popInfoContext()
|
popInfoContext()
|
||||||
closeScope(c) # close scope for parameters
|
closeScope(c) # close scope for parameters
|
||||||
popOwner()
|
popOwner()
|
||||||
#c.currentScope = oldScope
|
c.currentScope = oldScope
|
||||||
discard c.friendModules.pop()
|
discard c.friendModules.pop()
|
||||||
dec(c.instCounter)
|
dec(c.instCounter)
|
||||||
if result.kind == skMethod: finishMethod(c, result)
|
if result.kind == skMethod: finishMethod(c, result)
|
||||||
|
|
|
||||||
27
tests/generics/tdont_use_inner_scope.nim
Normal file
27
tests/generics/tdont_use_inner_scope.nim
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
|
||||||
|
# bug #2752
|
||||||
|
|
||||||
|
import future, sequtils
|
||||||
|
|
||||||
|
proc myFilter[T](it: (iterator(): T), f: (proc(anything: T):bool)): (iterator(): T) =
|
||||||
|
iterator aNameWhichWillConflict(): T {.closure.}=
|
||||||
|
for x in it():
|
||||||
|
if f(x):
|
||||||
|
yield x
|
||||||
|
result = aNameWhichWillConflict
|
||||||
|
|
||||||
|
|
||||||
|
iterator testIt():int {.closure.}=
|
||||||
|
yield -1
|
||||||
|
yield 2
|
||||||
|
|
||||||
|
#let unusedVariable = myFilter(testIt, (x: int) => x > 0)
|
||||||
|
|
||||||
|
proc onlyPos(it: (iterator(): int)): (iterator(): int)=
|
||||||
|
iterator aNameWhichWillConflict(): int {.closure.}=
|
||||||
|
var filtered = onlyPos(myFilter(it, (x:int) => x > 0))
|
||||||
|
for x in filtered():
|
||||||
|
yield x
|
||||||
|
result = aNameWhichWillConflict
|
||||||
|
|
||||||
|
let x = onlyPos(testIt)
|
||||||
4
todo.txt
4
todo.txt
|
|
@ -61,10 +61,8 @@ Bugs
|
||||||
|
|
||||||
- VM: Pegs do not work at compile-time
|
- VM: Pegs do not work at compile-time
|
||||||
- VM: ptr/ref T cannot work in general
|
- VM: ptr/ref T cannot work in general
|
||||||
- scopes are still broken for generic instantiation!
|
|
||||||
- blocks can "export" an identifier but the CCG generates {} for them ...
|
- blocks can "export" an identifier but the CCG generates {} for them ...
|
||||||
- ConcreteTypes in a 'case' means we don't check for duplicated case branches
|
- ConcreteTypes in a 'case' means we don't check for duplicated case branches
|
||||||
- typedesc matches a generic type T!
|
|
||||||
|
|
||||||
|
|
||||||
version 0.9.x
|
version 0.9.x
|
||||||
|
|
@ -79,8 +77,6 @@ version 0.9.x
|
||||||
- implement 'bits' pragmas
|
- implement 'bits' pragmas
|
||||||
- we need a magic thisModule symbol
|
- we need a magic thisModule symbol
|
||||||
- optimize 'genericReset'; 'newException' leads to code bloat
|
- optimize 'genericReset'; 'newException' leads to code bloat
|
||||||
- The 'do' notation might be trimmed so that its only purpose is to pass
|
|
||||||
multiple multi line constructs to a macro.
|
|
||||||
|
|
||||||
|
|
||||||
version 0.9.X
|
version 0.9.X
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue