Switch warnings to errors.
Update tests to let them not produce errors. Note that:
* base_nullable.nit have new error cases
* test_isa.nit add some test cases
* test_nil.nit is removed since it is to much outdated.
Signed-off-by: Jean Privat <jean@pryen.org>
for g in global_properties do
var p = self[g]
var t = p.signature.return_type
- if p isa MMAttribute and t != null and not t.is_nullable and v.tc.opt_warn.value > 0 then
- v.add_instr("if ({p.global.attr_access}(self) == NIT_NULL) fprintf(stderr, \"Uninitialized attribute %s at %s.\\n\", \"{p.full_name}\", from);")
+ if p isa MMAttribute and t != null and not t.is_nullable then
+ v.add_instr("if ({p.global.attr_access}(self) == NIT_NULL) \{ fprintf(stderr, \"Uninitialized attribute %s at %s.\\n\", \"{p.full_name}\", from); nit_exit(1); \}")
end
end
ctx_old.append(v.ctx)
meth compile_read_access(v: CompilerVisitor, n: PNode, recv: String): String
do
var res = "{global.attr_access}({recv}) /*{local_class}::{name}*/"
- if not signature.return_type.is_nullable and v.tc.opt_warn.value > 0 then
+ if not signature.return_type.is_nullable then
res = v.ensure_var(res, "{local_class}::{name}")
- v.add_instr("if ({res} == NIT_NULL) \{ fprintf(stderr, \"Uninitialized attribute %s\", \"{name}\"); {v.printf_locate_error(n)} } /* implicit isset */;")
+ v.add_instr("if ({res} == NIT_NULL) \{ fprintf(stderr, \"Uninitialized attribute %s\", \"{name}\"); {v.printf_locate_error(n)} nit_exit(1); } /* implicit isset */;")
end
return res
end
if subtype < stype then
return true
end
- # Do not enforce nullable subtype rules yet
- if subtype isa MMTypeNone or subtype.as_notnull < stype.as_notnull then
- warning(n, "Nullable type warning: expected {stype}, got {subtype}")
- return true
- end
error(n, "Type error: expected {stype}, got {subtype}")
return false
end
meth foo: U
with bar
do
- return null
+ return new U
end
end
(a isa A).output
(a isa Object).output
(not a isa B).output
-var c: Object = null
+(a isa nullable A).output
+(a isa nullable Object).output
+(not a isa nullable B).output
+var c: nullable Object = null
(c isa A).output
(c isa Object).output
(c isa B).output
+(c isa nullable A).output
+(c isa nullable Object).output
+(c isa nullable B).output
class A
type E: T
- readable writable attr _e: E = null
+ readable writable attr _e: nullable E = null
end
class B
class A
type E: T
- readable writable attr _e: E = null
+ readable writable attr _e: nullable E = null
end
class B
end
var b = new B
-var t: T
-var u = new U
+var t: nullable T
+var u: nullable U = new U
b.e = u
#alt1#u = b.e
class C
special A
- readable writable attr _tab: Array[E]
+ readable writable attr _tab: nullable Array[E]
init do end
end
class A
type E: F
type F: E
- readable writable attr _e: E
+ readable writable attr _e: nullable E = null
init do end
end
do
return _name
end
- attr _name: String = null
+ attr _name: String = "noname"
end
class WakeUpNode
do
_scheduler.add_event(self, d)
end
- attr _scheduler: Scheduler = null
+ attr _scheduler: Scheduler
end
class NodeSource
special Node
- attr _nexts: ArraySet[NodeSink] = null
+ attr _nexts: nullable ArraySet[NodeSink] = null
meth attach(n: NodeSink)
# Add the sink `n' the the connected nodes
# Do nothing if `n' is already connected
if _nexts == null then
return
end
- for n in _nexts do
+ for n in _nexts.as(not null) do
n.recieve(self)
end
end
#
class Scheduler
- attr _time_list: Array[Couple[Int, WakeUpNode]]
+ attr _time_list: Array[Couple[Int, WakeUpNode]] = new Array[Couple[Int, WakeUpNode]]
attr _time: Int = 0 # What time is it ?
meth add_event(n: WakeUpNode, d: Int)
# The node `n' whant to be weaked up in `d' time units
_time_list.add(entry)
end
- meth next_event: WakeUpNode
+ meth next_event: nullable WakeUpNode
# Get the
do
if _time_list.is_empty then
init
do
- _time_list = new Array[Couple[Int, WakeUpNode]]
end
end
class NodeAlternate
special NodeSink
special NodeSource
- attr _last: NodeSource
+ attr _last: nullable NodeSource
redef meth recieve(n: NodeSource)
do
if n != _last then
class A
- readable writable attr _val: Int
+ readable writable attr _val: Int = 0
meth hop(a: A, b: A, c: A)
do
if a.val > val then
class Rayon
private
- attr _stock: Array[Produit] = null # Des produits en stock
- attr _rubrique: String = null # La catégorie des produits stockés
+ attr _stock: Array[Produit] # Des produits en stock
+ attr _rubrique: String # La catégorie des produits stockés
# Cette fonction est utilisé par to_s pour afficher un petit titre
meth to_s_head: String
return s.to_s
end
- meth cherche_produit(n: String): Produit
+ meth cherche_produit(n: String): nullable Produit
do
var i = _stock.iterator
while i.is_ok do
# pour obtenir la quantité de clous dans le rayon, et :
# r.quantite("clous") = 15
# pour mettre le nombre de clous à 15
+
+ init do end
end
class RayonNormal
-Recieved signal 11
+Uninitialized attribute _a1 in base_attr_nullable_alt1::Foo::run (alt/base_attr_nullable_alt1.nit:38)
,---- Stack trace -- - - -
| base_attr_nullable_alt1::Foo::run (alt/base_attr_nullable_alt1.nit:36)
| base_attr_nullable_alt1::Foo::init (alt/base_attr_nullable_alt1.nit:48)
1
-Recieved signal 11
+Uninitialized attribute _a2 (alt/base_attr_nullable_alt2.nit:35)
,---- Stack trace -- - - -
+| base_attr_nullable_alt2::Foo::a2 (alt/base_attr_nullable_alt2.nit:35)
| base_attr_nullable_alt2::Foo::run (alt/base_attr_nullable_alt2.nit:36)
| base_attr_nullable_alt2::Foo::init (alt/base_attr_nullable_alt2.nit:48)
| base_attr_nullable_alt2::Sys::main (alt/base_attr_nullable_alt2.nit:81)
-Recieved signal 11
+Uninitialized attribute _a1 in base_attr_nullable_alt3::Bar::(base_attr_nullable_alt3::Foo::run) (alt/base_attr_nullable_alt3.nit:64)
,---- Stack trace -- - - -
| base_attr_nullable_alt3::Bar::(base_attr_nullable_alt3::Foo::run) (alt/base_attr_nullable_alt3.nit:62)
| base_attr_nullable_alt3::Bar::init (alt/base_attr_nullable_alt3.nit:69)
10
-Recieved signal 11
+Uninitialized attribute _a2 in base_attr_nullable_alt4::Foo::run_other (alt/base_attr_nullable_alt4.nit:45)
,---- Stack trace -- - - -
| base_attr_nullable_alt4::Foo::run_other (alt/base_attr_nullable_alt4.nit:42)
| base_attr_nullable_alt4::Bar::init (alt/base_attr_nullable_alt4.nit:69)
10
20
-Recieved signal 11
+Uninitialized attribute _a3 in base_attr_nullable_alt5::Bar::(base_attr_nullable_alt5::Foo::run) (alt/base_attr_nullable_alt5.nit:66)
,---- Stack trace -- - - -
| base_attr_nullable_alt5::Bar::(base_attr_nullable_alt5::Foo::run) (alt/base_attr_nullable_alt5.nit:62)
| base_attr_nullable_alt5::Bar::init (alt/base_attr_nullable_alt5.nit:69)
-0
-0
-1
-2
-10
-20
-30
+Uninitialized attribute _a1 in base_attr_nullable_int_alt1::Foo::run (alt/base_attr_nullable_int_alt1.nit:32)
+,---- Stack trace -- - - -
+| base_attr_nullable_int_alt1::Foo::run (alt/base_attr_nullable_int_alt1.nit:30)
+| base_attr_nullable_int_alt1::Foo::init (alt/base_attr_nullable_int_alt1.nit:42)
+| base_attr_nullable_int_alt1::Sys::main (alt/base_attr_nullable_int_alt1.nit:75)
+`------------------- - - -
1
-0
-1
-2
-10
-20
-30
+Uninitialized attribute _a2 (alt/base_attr_nullable_int_alt2.nit:29)
+,---- Stack trace -- - - -
+| base_attr_nullable_int_alt2::Foo::a2 (alt/base_attr_nullable_int_alt2.nit:29)
+| base_attr_nullable_int_alt2::Foo::run (alt/base_attr_nullable_int_alt2.nit:30)
+| base_attr_nullable_int_alt2::Foo::init (alt/base_attr_nullable_int_alt2.nit:42)
+| base_attr_nullable_int_alt2::Sys::main (alt/base_attr_nullable_int_alt2.nit:75)
+`------------------- - - -
-0
-0
-0
-1
-2
-10
-20
-30
+Uninitialized attribute _a1 in base_attr_nullable_int_alt3::Bar::(base_attr_nullable_int_alt3::Foo::run) (alt/base_attr_nullable_int_alt3.nit:58)
+,---- Stack trace -- - - -
+| base_attr_nullable_int_alt3::Bar::(base_attr_nullable_int_alt3::Foo::run) (alt/base_attr_nullable_int_alt3.nit:56)
+| base_attr_nullable_int_alt3::Bar::init (alt/base_attr_nullable_int_alt3.nit:63)
+| base_attr_nullable_int_alt3::Sys::main (alt/base_attr_nullable_int_alt3.nit:75)
+`------------------- - - -
10
-0
-1
-2
-10
-20
-30
+Uninitialized attribute _a2 in base_attr_nullable_int_alt4::Foo::run_other (alt/base_attr_nullable_int_alt4.nit:39)
+,---- Stack trace -- - - -
+| base_attr_nullable_int_alt4::Foo::run_other (alt/base_attr_nullable_int_alt4.nit:36)
+| base_attr_nullable_int_alt4::Bar::init (alt/base_attr_nullable_int_alt4.nit:63)
+| base_attr_nullable_int_alt4::Sys::main (alt/base_attr_nullable_int_alt4.nit:75)
+`------------------- - - -
10
20
-0
-1
-2
-10
-20
-30
+Uninitialized attribute _a3 in base_attr_nullable_int_alt5::Bar::(base_attr_nullable_int_alt5::Foo::run) (alt/base_attr_nullable_int_alt5.nit:60)
+,---- Stack trace -- - - -
+| base_attr_nullable_int_alt5::Bar::(base_attr_nullable_int_alt5::Foo::run) (alt/base_attr_nullable_int_alt5.nit:56)
+| base_attr_nullable_int_alt5::Bar::init (alt/base_attr_nullable_int_alt5.nit:63)
+| base_attr_nullable_int_alt5::Sys::main (alt/base_attr_nullable_int_alt5.nit:75)
+`------------------- - - -
true
true
true
+false
+false
+false
+true
+true
+true
+alt/base_nullable_alt1.nit:36,13--14: Type error: expected A, got nullable A
--- /dev/null
+alt/base_nullable_alt10.nit:55,18--21: Type error: expected Object, got null
+alt/base_nullable_alt6.nit:44,18--19: Type error: expected Object, got nullable A
+alt/base_nullable_alt7.nit:46,18--19: Type error: expected Object, got nullable Object
--- /dev/null
+alt/base_nullable_alt9.nit:53,13--16: Type error: expected A, got null
-alt/base_virtual_type2_alt1.nit:46,5--7: Type error: expected U, got T
+alt/base_virtual_type2_alt1.nit:46,5--7: Type error: expected nullable U, got nullable T
-alt/base_virtual_type4_alt1.nit:24,8--12: Type error: expected U, got T
+alt/base_virtual_type4_alt1.nit:24,8--12: Type error: expected nullable U, got T
-alt/base_virtual_type5_alt1.nit:26,7--7: Type error: expected U, got Int
+alt/base_virtual_type5_alt1.nit:26,7--7: Type error: expected nullable U, got Int
-alt/base_virtual_type5_alt2.nit:27,7--11: Type error: expected U, got T
+alt/base_virtual_type5_alt2.nit:27,7--11: Type error: expected nullable U, got T
-alt/base_virtual_type_alt1.nit:39,5--7: Type error: expected Int, got T
+alt/base_virtual_type_alt1.nit:39,5--7: Type error: expected Int, got nullable T
-alt/base_virtual_type_alt2.nit:40,7--7: Type error: expected T, got Int
+alt/base_virtual_type_alt2.nit:40,7--7: Type error: expected nullable T, got Int
-alt/base_virtual_type_alt3.nit:43,7--7: Type error: expected T, got B
+alt/base_virtual_type_alt3.nit:43,7--7: Type error: expected nullable T, got B
+++ /dev/null
-01
\ No newline at end of file
# contributed by Jean Privat
class TreeNode
- attr _left: TreeNode
- attr _right: TreeNode
+ attr _left: nullable TreeNode
+ attr _right: nullable TreeNode
attr _item: Int
- init(left: TreeNode, right: TreeNode, item: Int)
+ init(left: nullable TreeNode, right: nullable TreeNode, item: Int)
do
_left = left
_right = right
end
var stretch_depth = max_depth + 1
-var stretch_tree = bottom_up_tree(0, stretch_depth)
+var stretch_tree: nullable TreeNode = bottom_up_tree(0, stretch_depth)
print("stretch tree of depth {stretch_depth}\t check: {stretch_tree.item_check}")
# limitations under the License.
class A
- attr _attribute: A
+ attr _attribute: nullable A
attr _num: Char
- meth foo=(a: A)
+ meth foo=(a: nullable A)
do
_attribute = a
end
- meth foo: A
+ meth foo: nullable A
do
return _attribute
end
- meth bar=(c: Char, a: A)
+ meth bar=(c: Char, a: nullable A)
do
_num = c
_attribute = a
end
- meth bar(c: Char): A
+ meth bar(c: Char): nullable A
do
if c == _num then
return _attribute
_num = '*'
end
- init init2(c: Char, a: A)
+ init init2(c: Char, a: nullable A)
do
_num = c
_attribute = a
print(not a is b)
print("* null")
-a = null
-b = null
+var a1: nullable Object = null
+var b1: nullable Object = null
print(not null is s)
print(not s is null)
-print(not a is s)
-print(not s is a)
+print(not a1 is s)
+print(not s is a1)
print(null is null)
-print(b is null)
-print(b is a)
+print(b1 is null)
+print(b1 is a1)
print(not i is null)
-print(not i is a)
+print(not i is a1)
print(not null is i)
-print(not a is i)
+print(not a1 is i)
init do end
end
-var a = new A
-var b: A = null
+var a: nullable A = new A
+var b: nullable A = null
if a == null then printn(0) else printn(1)
if a is null then printn(0) else printn(1)
#if b == null then printn(1) else printn(0)
meth f: F do return _f_ end
meth f=(x: F) do _f_ = x end
- init do end
+ init(e:E) do _e = e
end
class Gen2[G: Int]
special Gen1[G, Char]
-
- init do end
+ init(e:G) do super(e)
end
class Gen3[H: Int]
special Gen1[H, Char]
redef readable redef writable redef attr _e: H
- redef attr _f_: Char
+ redef attr _f_: Char = 'N'
redef meth f: Char do return _f_ end
redef meth f=(x: Char) do _f_ = x end
- init do end
+ init(e:H) do super(e)
end
-var g1 = new Gen1[Int, Char]
-var g2 = new Gen2[Int]
-var g3 = new Gen3[Int]
+var g1 = new Gen1[Int, Char](1)
+var g2 = new Gen2[Int](2)
+var g3 = new Gen3[Int](3)
g1.e = 1
g1.f = '1'
g2.e = 2
print(a2 isa Object)
print("null:")
-var a3: Object = null
-print(a3 isa Int)
-print(a3 isa String)
-print(a3 isa AbstractArray[Char])
-print(a3 isa Iterator[Int])
-print(a3 isa Discrete)
-print(a3 isa Object)
+var a3: nullable Object = null
+print(a3 isa nullable Int)
+print(a3 isa nullable String)
+print(a3 isa nullable AbstractArray[Char])
+print(a3 isa nullable Iterator[Int])
+print(a3 isa nullable Discrete)
+print(a3 isa nullable Object)
+++ /dev/null
-# This file is part of NIT ( http://www.nitlanguage.org ).
-#
-# Copyright 2004-2008 Jean Privat <jean@pryen.org>
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-
-var a: Object = null
-var b: Object = null
-var c = a
-var d = "coucou"
-d = null
-printn(0)
-printn(null)
-printn(a)
-printn(b)
-printn(c)
-printn(d)
-printn(1)
end
end
-var a: A = null
+var a: nullable A = null
if a != null then
a.foo
a.bar.output
# limitations under the License.
class A
- attr _foo: Object
- attr _bar: A
- attr _baz: Int
+ attr _foo: nullable Object
+ attr _bar: nullable A
+ attr _baz: nullable Int
redef meth output do 'A'.output end
init do end
class B
special A
- redef attr _foo: Int
- redef attr _bar: B
+ redef attr _foo: nullable Int
+ redef attr _bar: nullable B
redef meth output do 'B'.output end
init do end