File tree Expand file tree Collapse file tree 2 files changed +51
-14
lines changed Expand file tree Collapse file tree 2 files changed +51
-14
lines changed Original file line number Diff line number Diff line change 1+ struct None {}
2+
3+ type Myfn = fn (int ) int
4+
5+ type Myfnfact = fn () Myfn
6+
7+ type Maybefnfact = Myfnfact | None
8+
9+ // Myfn
10+ fn abc (i int ) int {
11+ return i
12+ }
13+
14+ // create Myfn
15+ fn myfnfact () Myfn {
16+ return abc
17+ }
18+
19+ // run fn if exists
20+ fn run (mmff Maybefnfact) string {
21+ match mmff {
22+ Myfnfact {
23+ r := mmff ()
24+ return 'yes fn: ${r} '
25+ }
26+ None {
27+ return 'None fn'
28+ }
29+ }
30+ }
31+
32+ fn test_sumtype_with_alias_fntype_fn_call () {
33+ r1 := main.myfnfact ()(1 )
34+ println (r1 )
35+ assert r1 == 1
36+
37+ r2 := run (None{})
38+ println (r2 )
39+ assert r2 == 'None fn'
40+
41+ r3 := run (myfnfact)
42+ println (r3 )
43+ assert r3 == 'yes fn: fn (int) int'
44+ }
Original file line number Diff line number Diff line change @@ -11,25 +11,18 @@ fn abc(i int) int {
1111 return i
1212}
1313
14- // create Myfn
15- fn myfnfact () Myfn {
16- return abc
17- }
18-
19- // run fn if exists
2014fn run (mmff Maybefnfact) string {
2115 match mmff {
22- Myfnfact {
23- r := mmff ()
24- return 'yes fn: ${r} '
25- }
26- None {
27- return 'None fn'
28- }
16+ Myfnfact { return 'yes fn' }
17+ None { return 'None fn' }
2918 }
3019}
3120
3221fn test_sumtype_with_alias_fntype () {
22+ // create Myfn
23+ myfnfact := fn () Myfn {
24+ return abc
25+ }
3326 r1 := main.myfnfact ()(1 )
3427 println (r1 )
3528 assert r1 == 1
@@ -40,5 +33,5 @@ fn test_sumtype_with_alias_fntype() {
4033
4134 r3 := run (myfnfact)
4235 println (r3 )
43- assert r3 == 'yes fn: fn (int) int '
36+ assert r3 == 'yes fn'
4437}
You can’t perform that action at this time.
0 commit comments