diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/concepts/tconceptinclosure.nim | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/concepts/tconceptinclosure.nim b/tests/concepts/tconceptinclosure.nim new file mode 100644 index 000000000..ccd19d201 --- /dev/null +++ b/tests/concepts/tconceptinclosure.nim @@ -0,0 +1,33 @@ +discard """ + output: "10\n20" +""" + +type + FonConcept = concept x + x.x is int + + Implementation = object + x: int + + Closure = object + f: proc() + +proc f1(x: FonConcept): Closure = + result.f = proc () = + echo x.x + +proc f2(x: FonConcept): Closure = + result.f = proc () = + echo x.x + +let x = Implementation(x: 10) +let y = Implementation(x: 20) + +let a = x.f1 +let b = x.f2 +let c = x.f1 +let d = y.f2 + +a.f() +d.f() + |