lib: Array::== do not return false if the dynamic types of the arrays differ
authorJean Privat <jean@pryen.org>
Wed, 2 May 2012 02:11:31 +0000 (22:11 -0400)
committerJean Privat <jean@pryen.org>
Wed, 2 May 2012 15:44:13 +0000 (11:44 -0400)
This modification is in fact useless for the current compiler that has
wrong dynamic types but is required by the new interpreter.

Signed-off-by: Jean Privat <jean@pryen.org>

lib/standard/collection/array.nit
tests/sav/test_array_eq.sav [new file with mode: 0644]
tests/test_array_eq.nit [new file with mode: 0644]

index f9ed504..4def87b 100644 (file)
@@ -141,7 +141,7 @@ abstract class AbstractArrayRead[E]
        # Two arrays are equals if they have the same items in the same order.
        redef fun ==(o)
        do
-               if not o isa AbstractArray[E] or o is null then return false
+               if not o isa AbstractArray[nullable Object] or o is null then return false
                var l = length
                if o.length != l then return false
                var i = 0
diff --git a/tests/sav/test_array_eq.sav b/tests/sav/test_array_eq.sav
new file mode 100644 (file)
index 0000000..b979d62
--- /dev/null
@@ -0,0 +1,3 @@
+true
+true
+true
diff --git a/tests/test_array_eq.nit b/tests/test_array_eq.nit
new file mode 100644 (file)
index 0000000..0958380
--- /dev/null
@@ -0,0 +1,25 @@
+# This file is part of NIT ( http://www.nitlanguage.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 = ["a"]
+var b = new Array[Object]
+b.add("a")
+print a == b
+
+b.add("c")
+print a != b
+
+var c = new List[String]
+c.add("a")
+print a != b