Merge: doc: fixed some typos and other misc. corrections
[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
33 redef fun to_s
34 do
35 # cname without generics (for erasure compiler)
36 var cname = class_name.split('[')[0]
37 return "<{cname}>"
38 end
39 end
40
41 class Y
42 var quux: Object = self
43 end
44
45 var x
46
47 # self is the implicit receiver
48 x = &foo
49 x = &foo.bar
50 x = &foo.bar.baz
51 x = (&foo.bar).baz
52 x = &(foo.bar).baz
53
54 var y = new Y
55 #alt1#x = &y # error since y is a variable
56 x = &y.foo
57 x = &y.foo.bar
58 x = &y.foo.bar.baz
59 x = (&y.foo.bar).baz
60 x = &(y.foo.bar).baz
61
62 x = &y.quux