Skip to content

Commit 82f37bf

Browse files
committed
tests: Add specific test for closures in native emitter.
1 parent fa5950e commit 82f37bf

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# test native emitter can handle closures correctly
2+
3+
# basic closure
4+
@micropython.native
5+
def f():
6+
x = 1
7+
@micropython.native
8+
def g():
9+
nonlocal x
10+
return x
11+
return g
12+
print(f()())
13+
14+
# closing over an argument
15+
@micropython.native
16+
def f(x):
17+
@micropython.native
18+
def g():
19+
nonlocal x
20+
return x
21+
return g
22+
print(f(2)())
23+
24+
# closing over an argument and a normal local
25+
@micropython.native
26+
def f(x):
27+
y = 2 * x
28+
@micropython.native
29+
def g(z):
30+
return x + y + z
31+
return g
32+
print(f(2)(3))
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
1
2+
2
3+
9

0 commit comments

Comments
 (0)