Skip to content

Commit 43f4e57

Browse files
committed
Merge branch 'master' into collections_contract
2 parents afbc581 + 15e804c commit 43f4e57

File tree

207 files changed

+7444
-2395
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

207 files changed

+7444
-2395
lines changed

.gitlab-ci.yml

+15
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ services:
77

88
variables:
99
NEO4J_AUTH: none
10+
POSTGRES_HOST_AUTH_METHOD: trust
1011

1112
cache:
1213
paths:
@@ -333,6 +334,20 @@ bench_fast:
333334
- benchmarks/*.gnu
334335
when: always
335336

337+
nitunit_manual:
338+
stage: more_test
339+
dependencies:
340+
- build_tools
341+
script:
342+
- nitunit doc/manual/*.nit
343+
- junit2html nitunit.xml
344+
artifacts:
345+
paths:
346+
- nitunit.xml*
347+
when: always
348+
reports:
349+
junit:
350+
- nitunit.xml
336351

337352
# MORE TOOLS ########################################################
338353

contrib/pep8analysis/src/parser/lexer.nit

+1-1
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ redef class AError
255255

256256
init init_error(message: String, loc: Location)
257257
do
258-
init(loc)
258+
self.location = loc
259259
self.message = message
260260
end
261261
end

doc/manual/attribute.md

+15-15
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ end
1616

1717
Note that from an API point of view, there is no way to distinguish the read access of an attribute with a normal method neither to distinguish a write access of an attribute with a setter. Therefore, the read access of an attribute is called a getter while the write access is called a setter.
1818

19-
~~~
19+
~~~nitish
2020
var x = foo.bar # Is bar an attribute or a method?
2121
foo.bar = y # Is bar an attribute or a setter?
2222
# In fact, we do not need to know.
@@ -28,12 +28,12 @@ By default, a getter is public and a setter is private. The visibility of getter
2828
additional `writable` keyword.
2929

3030
~~~
31-
class Foo
32-
var pub_pri: X
33-
protected var pro_pri: X
34-
var pub_pub: X is writable
35-
private var pri_pro: X is protected writable
36-
var pub_pri2: X is private writable # the default
31+
class Foo2
32+
var pub_pri: Int
33+
protected var pro_pri: Int
34+
var pub_pub: Int is writable
35+
private var pri_pro: Int is protected writable
36+
var pub_pri2: Int is private writable # the default
3737
end
3838
~~~
3939

@@ -43,17 +43,17 @@ Getters and setters of attributes behave like genuine methods that can be inheri
4343
a redefinition while `redef writable` declares that the setter is a redefinition.
4444

4545
~~~
46-
interface Foo
46+
interface Foo3
4747
fun derp: Int is abstract
4848
fun derp=(o: Int) is abstract
4949
end
50-
class Bar
51-
super Foo
52-
redef var derp: Int redef writable
50+
class Bar3
51+
super Foo3
52+
redef var derp is redef writable
5353
end
54-
class Baz
55-
super Bar
56-
redef fun derp do ...
57-
redef fun derp=(o) do ...
54+
class Baz3
55+
super Bar3
56+
redef fun derp do return 1
57+
redef fun derp=(o) do end
5858
end
5959
~~~

doc/manual/constructor.md

+53-7
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ assert p.id == "ABC"
2727
In subclasses, additional attributes are automatically collected.
2828

2929
~~~
30+
class Product
31+
var id: String
32+
var description: String
33+
var price: Float
34+
end
3035
class Book
3136
super Product
3237
var author: String
@@ -44,6 +49,11 @@ It is used to perform additional systematic tasks.
4449
Because the `init` is run at the end of the initialization sequence, initialized attributes are usable in the body.
4550

4651
~~~
52+
class Product
53+
var id: String
54+
var description: String
55+
var price: Float
56+
end
4757
class OverpricedProduct
4858
super Product
4959
init
@@ -52,7 +62,7 @@ class OverpricedProduct
5262
end
5363
end
5464
var op = new OverpricedProduct("ABC", "Bla bla", 15.95)
55-
assert op.price == 159.50
65+
assert op.price.is_approx(159.50, 0.001)
5666
~~~
5767

5868

@@ -65,6 +75,11 @@ There is three cases for an attributes to not be collected in the `new`.
6575
* Attributes introduced in refinement of classes
6676

6777
~~~
78+
class Product
79+
var id: String
80+
var description: String
81+
var price: Float
82+
end
6883
class TaxedProduct
6984
super Product
7085
var tax_rate = 9.90
@@ -75,7 +90,7 @@ class TaxedProduct
7590
end
7691
end
7792
var tp = new TaxedProduct("ABC", "Bla bla", 15.95)
78-
assert tp.total_price == 17.52905
93+
assert tp.total_price.is_approx(17.52905, 0.00001)
7994
~~~
8095

8196
Note: The orchestration here is important. In order, the following is executed:
@@ -95,6 +110,11 @@ In fact, by default, the setter of an attribute is used as a initializer.
95110
`autoinit` is used to register a method as a setter.
96111

97112
~~~
113+
class Product
114+
var id: String
115+
var description: String
116+
var price: Float
117+
end
98118
class FooProduct
99119
super Product
100120
fun set_xy(x, y: Int) is autoinit do z = x * 10 + y
@@ -113,15 +133,41 @@ In most case, there is no reason that an argument of a `new` construction is not
113133
As explained above, one of the main advantage of these constructors is their compatibility with multiple inheritance.
114134

115135
~~~
136+
class Product
137+
var id: String
138+
var description: String
139+
var price: Float
140+
end
141+
class OverpricedProduct
142+
super Product
143+
init
144+
do
145+
price = price * 10.0
146+
end
147+
end
148+
class TaxedProduct
149+
super Product
150+
var tax_rate = 9.90
151+
var total_price: Float is noinit
152+
init
153+
do
154+
total_price = price * (1.0 + tax_rate/100.0)
155+
end
156+
end
157+
class FooProduct
158+
super Product
159+
fun set_xy(x, y: Int) is autoinit do z = x * 10 + y
160+
var z: Int is noinit
161+
end
116162
class MultiProduct
117163
super OverpricedProduct
118164
super TaxedProduct
119165
super FooProduct
120166
end
121167
var mp = new MultiProduct("ABC", "Bla bla", 15.96, 1, 3)
122168
assert mp.id == "ABC"
123-
assert mp.price == 159.6
124-
assert mp.total_price == 175.4
169+
assert mp.price.is_approx(159.6, 0.001)
170+
assert mp.total_price.is_approx(175.4, 0.001)
125171
assert mp.z == 13
126172
~~~
127173

@@ -151,11 +197,11 @@ class Point
151197
redef fun to_s do return "({x},{y})"
152198
end
153199
var p1 = new Point(1.0, 2.0)
154-
assert p1.to_s == "(1,2)"
200+
assert p1.to_s == "(1.0,2.0)"
155201
var p2 = new Point.origin
156-
assert p2.to_s == "(0,0)"
202+
assert p2.to_s == "(0.0,0.0)"
157203
var p3 = new Point.polar(1.0, 2.0)
158-
assert p3.to_s == "(-0.4161,0.9092)"
204+
assert p3.to_s == "(-0.416,0.909)"
159205
~~~
160206

161207

doc/manual/method.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
`fun` declares methods. Methods must have a name, may have parameters, and may have a return type. Parameters are typed; however, a single type can be used for multiple parameters.
44

5-
~~~
6-
fun foo(x, y: Int, s: String): Bool ...
5+
~~~nitish
6+
fun foo(x, y: Int, s: String): Bool # ...
77
~~~
88

99
`do` declares the body of methods. Alike control structures, a one-liner version is available.
@@ -38,7 +38,7 @@ print a.length # no () for length, no () for print
3838

3939
However, this last facility requires that the first argument does not start with a parenthesis or a bracket.
4040

41-
~~~
41+
~~~nitish
4242
foo (x).bar # will be interpreted as (foo(x)).bar
4343
foo [x].bar # will be interpreted as (foo[x]).bar
4444
~~~
@@ -140,7 +140,7 @@ Operators and setters are methods that require a special syntax for their defini
140140

141141
<!-- -->
142142

143-
~~~
143+
~~~nitish
144144
class Foo
145145
fun +(a: Bar): Baz do ...
146146
fun -: Baz do ...
@@ -162,7 +162,7 @@ a[b] = c # The bracket setter '[]='
162162

163163
`+=` and `-=` are combinations of the assignment (`=`) and a binary operator. These feature are extended to setters where a single `+=` is in fact three method calls: a function call, the operator call, then a setter call.
164164

165-
~~~
165+
~~~nitish
166166
a += c # equiv. a = a + c
167167
a[b] += c # equiv. a[b] = a[b] + c
168168
a.foo += c # equiv. a.foo = a.foo + c

doc/manual/module.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ intrude importers), there is still no restriction.
3131

3232
Visibility of attributes is more specific and is detailed in its own section.
3333

34-
~~~
34+
~~~nitish
3535
module m1
3636
class Foo
3737
fun pub do ...
@@ -55,7 +55,7 @@ y.pri2
5555

5656
<!-- -->
5757

58-
~~~
58+
~~~nitish
5959
module m2
6060
import m1
6161
class Baz

0 commit comments

Comments
 (0)