37c971f9b269b14fe5ef7684da70888cab957384
[nit.git] / tests / syntax_callref.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 import functional
15
16 redef class Object
17 fun foo: Object
18 do
19 print "foo{self}"
20 return self
21 end
22 fun bar: Object
23 do
24 print "baz{self}"
25 return self
26 end
27 fun baz: Object
28 do
29 print "baz{self}"
30 return self
31 end
32 end
33
34 class Y
35 var quux: Object = self
36 end
37
38 var x
39
40 # self is the implicit receiver
41 x = &foo
42 x = &foo.bar
43 x = &foo.bar.baz
44 x = (&foo.bar).baz
45 x = &(foo.bar).baz
46
47 var y = new Y
48 #_lt1#x = &y # error since y is a variable TODO: put `alt1` back
49 x = &y.foo
50 x = &y.foo.bar
51 x = &y.foo.bar.baz
52 x = (&y.foo.bar).baz
53 x = &(y.foo.bar).baz
54
55 x = &y.quux