From ce2bb6ed6d8ec532510ac9e7a51296700810bfb0 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Tue, 1 May 2012 22:11:31 -0400 Subject: [PATCH] lib: Array::== do not return false if the dynamic types of the arrays differ 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 --- lib/standard/collection/array.nit | 2 +- tests/sav/test_array_eq.sav | 3 +++ tests/test_array_eq.nit | 25 +++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 tests/sav/test_array_eq.sav create mode 100644 tests/test_array_eq.nit diff --git a/lib/standard/collection/array.nit b/lib/standard/collection/array.nit index f9ed504..4def87b 100644 --- a/lib/standard/collection/array.nit +++ b/lib/standard/collection/array.nit @@ -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 index 0000000..b979d62 --- /dev/null +++ b/tests/sav/test_array_eq.sav @@ -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 index 0000000..0958380 --- /dev/null +++ b/tests/test_array_eq.nit @@ -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 -- 1.7.9.5