tests: add syntax_lambda to check various forms
[nit.git] / tests / syntax_lambda.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 class A
16 fun foo(any: Object) do end
17 end
18
19 class B
20 end
21
22 fun bar(any: Object) do end
23
24 var a = fun do end
25
26 var b = fun do print 1 end
27 #alt1# var b2 = fun do print 1 # mandatory end
28 var b3 = (fun do print 1 end)
29 #alt2# var b3 = (fun do print 1) # still mandatory end
30
31 var c = fun do
32 print 1
33 return
34 end
35
36 var d = fun(a: A) do print 1 end
37 var d2 = fun(a) do print 1 end # might be a sematic error but is legal syntax
38
39 var e = fun: A do return new A end
40
41 var f = fun(a: A, b: B...): C do return a.foo(b) end
42
43 var g = [fun: Int do return 1 end, fun: Int do return 2 end]
44
45 bar(fun do print 1 end)
46 bar fun do print 1 end
47
48 bar(
49 fun
50 do
51 print 1
52 end
53 )
54
55 (fun do print 1 end).bar
56 fun do print 1 end.bar # this is unexpectedly legal
57
58 var z = fun do
59 return fun do
60 return 1
61 end
62 end
63
64 fun do fun do end.foo fun do end end.bar # hmmm