Add also some tests.
Signed-off-by: Jean Privat <jean@pryen.org>
# Conformance is granted if among them there is a most general type
# Return the most general type if a conformance is found
# Display an error and return null if no conformance is found
+ # The only allowed combinaison is with the nullable marker
# @param stype is a possible additional type (without node)
# Examples:
# Int, Int, Object => return Object
# Int, Float => display error, return null
+ # nullable Int, Object => return nullable Object
meth check_conform_multiexpr(stype: MMType, nodes: Collection[PExpr]): MMType
do
var node: PExpr = null # candidate node
for n in nodes do
if not check_expr(n) then return null
var ntype = n.stype
+ if stype != null and stype.is_nullable != ntype.is_nullable then
+ # nullable combinaison: if one of them is nulable, considers that both are
+ stype = stype.as_nullable
+ ntype = ntype.as_nullable
+ end
if stype == null or (ntype != null and stype < ntype) then
stype = ntype
node = n
--- /dev/null
+alt/test_array_comb_alt1.nit:23,19--21: Type error: no most general type. Got String and nullable Int at alt/test_array_comb_alt1.nit:23,16--16.
--- /dev/null
+alt/test_array_comb_alt2.nit:24,19--21: Type error: no most general type. Got String and nullable Int at alt/test_array_comb_alt2.nit:24,16--16.
--- /dev/null
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Copyright 2009 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 = [5, null]
+var b = [null, 5]
+var c: nullable Int = 5
+var d = [5, c]
+var e = [c, 5]
+var f = [c, null]
+#alt1#var g = [null, 5, "5"]
+#alt2#var h = [null, c, "5"]