syntax: comparing a variable with null makes it evolve to null
authorJean Privat <jean@pryen.org>
Fri, 8 Jan 2010 22:09:04 +0000 (17:09 -0500)
committerJean Privat <jean@pryen.org>
Thu, 14 Jan 2010 16:43:41 +0000 (11:43 -0500)
Signed-off-by: Jean Privat <jean@pryen.org>

src/syntax/typing.nit
tests/base_var_type_evolution_null2.nit [new file with mode: 0644]
tests/sav/base_var_null_alt10.sav [new file with mode: 0644]
tests/sav/base_var_null_alt11.sav [new file with mode: 0644]
tests/sav/base_var_null_alt12.sav [new file with mode: 0644]
tests/sav/base_var_null_alt9.sav [new file with mode: 0644]
tests/sav/base_var_type_evolution_null2.sav [new file with mode: 0644]
tests/sav/base_var_type_evolution_null2_alt1.sav [new file with mode: 0644]
tests/sav/base_var_type_evolution_null2_alt2.sav [new file with mode: 0644]

index 5e75e57..f004491 100644 (file)
@@ -1463,6 +1463,7 @@ redef class AEqExpr
                var variable = n.its_variable
                if variable != null then
                        _if_false_variable_ctx = v.variable_ctx.sub_with(self, variable, n.stype.as_notnull)
+                       _if_true_variable_ctx = v.variable_ctx.sub_with(self, variable, v.type_none)
                end
        end
 end
@@ -1493,6 +1494,7 @@ redef class ANeExpr
                var variable = n.its_variable
                if variable != null then
                        _if_true_variable_ctx = v.variable_ctx.sub_with(self, variable, n.stype.as_notnull)
+                       _if_false_variable_ctx = v.variable_ctx.sub_with(self, variable, v.type_none)
                end
        end
 end
diff --git a/tests/base_var_type_evolution_null2.nit b/tests/base_var_type_evolution_null2.nit
new file mode 100644 (file)
index 0000000..b1088a9
--- /dev/null
@@ -0,0 +1,42 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Copyright 2010 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.
+
+import kernel
+
+class A
+end
+
+fun rand: Bool do return true
+
+fun eat_na(a: nullable A) do 'a'.output
+fun eat_a(a: A) do 'A'.output
+
+var a: nullable Object
+a = null
+if rand then
+       a = new A
+end
+
+if a == null then
+       eat_na(a)
+       #alt1#eat_a(a)
+       '\n'.output
+       abort#!alt2#
+end
+eat_na(a)
+eat_a(a)
+'\n'.output
+
diff --git a/tests/sav/base_var_null_alt10.sav b/tests/sav/base_var_null_alt10.sav
new file mode 100644 (file)
index 0000000..b88df43
--- /dev/null
@@ -0,0 +1 @@
+alt/base_var_null_alt10.nit:43,2--7: Error: Attribute '_foo' access on 'null'.
diff --git a/tests/sav/base_var_null_alt11.sav b/tests/sav/base_var_null_alt11.sav
new file mode 100644 (file)
index 0000000..29ca51e
--- /dev/null
@@ -0,0 +1 @@
+alt/base_var_null_alt11.nit:44,2--11: Error: Attribute '_foo' access on 'null'.
diff --git a/tests/sav/base_var_null_alt12.sav b/tests/sav/base_var_null_alt12.sav
new file mode 100644 (file)
index 0000000..2f2ee8f
--- /dev/null
@@ -0,0 +1 @@
+alt/base_var_null_alt12.nit:45,2--7: Error: Method '+' call on 'null'.
diff --git a/tests/sav/base_var_null_alt9.sav b/tests/sav/base_var_null_alt9.sav
new file mode 100644 (file)
index 0000000..33b5944
--- /dev/null
@@ -0,0 +1 @@
+alt/base_var_null_alt9.nit:42,2--9: Error: Method 'output' call on 'null'.
diff --git a/tests/sav/base_var_type_evolution_null2.sav b/tests/sav/base_var_type_evolution_null2.sav
new file mode 100644 (file)
index 0000000..7ac5efc
--- /dev/null
@@ -0,0 +1 @@
+aA
diff --git a/tests/sav/base_var_type_evolution_null2_alt1.sav b/tests/sav/base_var_type_evolution_null2_alt1.sav
new file mode 100644 (file)
index 0000000..41b285c
--- /dev/null
@@ -0,0 +1 @@
+alt/base_var_type_evolution_null2_alt1.nit:35,8: Type error: expected A, got null
diff --git a/tests/sav/base_var_type_evolution_null2_alt2.sav b/tests/sav/base_var_type_evolution_null2_alt2.sav
new file mode 100644 (file)
index 0000000..a5b4d7c
--- /dev/null
@@ -0,0 +1 @@
+alt/base_var_type_evolution_null2_alt2.nit:39,7: Type error: expected A, got nullable A