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