mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
…var/let symbols
fixes #22939
fixes #16890
Besides, it was applied to let/const/var with pragmas, now it is
universally applied.
```nim
{.push exportc.}
proc foo =
let bar = 12
echo bar
{.pop.}
```
For example, the `bar` variable will be affected by `exportc`.
(cherry picked from commit cecaf9c56b)
This commit is contained in:
@@ -536,6 +536,12 @@ proc semIdentWithPragma(c: PContext, kind: TSymKind, n: PNode,
|
||||
else: discard
|
||||
else:
|
||||
result = semIdentVis(c, kind, n, allowed)
|
||||
case kind
|
||||
of skField: implicitPragmas(c, result, n.info, fieldPragmas)
|
||||
of skVar: implicitPragmas(c, result, n.info, varPragmas)
|
||||
of skLet: implicitPragmas(c, result, n.info, letPragmas)
|
||||
of skConst: implicitPragmas(c, result, n.info, constPragmas)
|
||||
else: discard
|
||||
|
||||
proc checkForOverlap(c: PContext, t: PNode, currentEx, branchIndex: int) =
|
||||
let ex = t[branchIndex][currentEx].skipConv
|
||||
|
||||
@@ -4,6 +4,7 @@ when defined(cpp):
|
||||
{.push header: "<vector>".}
|
||||
type
|
||||
Vector[T] {.importcpp: "std::vector".} = object
|
||||
{.pop.}
|
||||
elif defined(js):
|
||||
proc endsWith*(s, suffix: cstring): bool {.noSideEffect,importjs: "#.endsWith(#)".}
|
||||
elif defined(c):
|
||||
|
||||
@@ -11,6 +11,23 @@ type # for capture test, ref #20679
|
||||
FooCapture = ref object
|
||||
x: int
|
||||
|
||||
proc mainProc() =
|
||||
block: # bug #16967
|
||||
var s = newSeq[proc (): int](5)
|
||||
{.push exportc.}
|
||||
proc bar() =
|
||||
for i in 0 ..< s.len:
|
||||
let foo = i + 1
|
||||
capture foo:
|
||||
s[i] = proc(): int = foo
|
||||
{.pop.}
|
||||
|
||||
bar()
|
||||
|
||||
for i, p in s.pairs:
|
||||
let foo = i + 1
|
||||
doAssert p() == foo
|
||||
|
||||
template main() =
|
||||
block: # `=>`
|
||||
block:
|
||||
@@ -85,22 +102,6 @@ template main() =
|
||||
closure2 = () => (i, j)
|
||||
doAssert closure2() == (5, 3)
|
||||
|
||||
block: # bug #16967
|
||||
var s = newSeq[proc (): int](5)
|
||||
{.push exportc.}
|
||||
proc bar() =
|
||||
for i in 0 ..< s.len:
|
||||
let foo = i + 1
|
||||
capture foo:
|
||||
s[i] = proc(): int = foo
|
||||
{.pop.}
|
||||
|
||||
bar()
|
||||
|
||||
for i, p in s.pairs:
|
||||
let foo = i + 1
|
||||
doAssert p() == foo
|
||||
|
||||
block: # issue #20679
|
||||
# this should compile. Previously was broken as `var int` is an `nnkHiddenDeref`
|
||||
# which was not handled correctly
|
||||
@@ -270,17 +271,16 @@ template main() =
|
||||
discard collect(newSeq, for i in 1..3: i)
|
||||
foo()
|
||||
|
||||
proc mainProc() =
|
||||
block: # dump
|
||||
# symbols in templates are gensym'd
|
||||
let
|
||||
x = 10
|
||||
y = 20
|
||||
x {.inject.} = 10
|
||||
y {.inject.} = 20
|
||||
dump(x + y) # x + y = 30
|
||||
|
||||
block: # dumpToString
|
||||
template square(x): untyped = x * x
|
||||
let x = 10
|
||||
let x {.inject.} = 10
|
||||
doAssert dumpToString(square(x)) == "square(x): x * x = 100"
|
||||
let s = dumpToString(doAssert 1+1 == 2)
|
||||
doAssert "failedAssertImpl" in s
|
||||
|
||||
Reference in New Issue
Block a user