nitg/niti: Fixed cast problem when using object_id on Bool and Char classes, added...
authorLucas Bajolet <r4pass@hotmail.com>
Fri, 20 Sep 2013 14:18:36 +0000 (10:18 -0400)
committerLucas Bajolet <r4pass@hotmail.com>
Fri, 20 Sep 2013 14:18:36 +0000 (10:18 -0400)
Signed-off-by: Lucas Bajolet <r4pass@hotmail.com>

src/abstract_compiler.nit
tests/base_test_obj_id.nit [new file with mode: 0644]
tests/sav/base_test_obj_id.res [new file with mode: 0644]
tests/sav/base_test_obj_id.sav [new file with mode: 0644]

index 1a2fc8c..9786db1 100644 (file)
@@ -1406,7 +1406,7 @@ redef class AInternMethPropdef
                                v.add("printf(\"%c\", {arguments.first});")
                                return
                        else if pname == "object_id" then
-                               v.ret(arguments.first)
+                               v.ret(v.new_expr("(long){arguments.first}", ret.as(not null)))
                                return
                        else if pname == "+" then
                                v.ret(v.new_expr("{arguments[0]} + {arguments[1]}", ret.as(not null)))
@@ -1451,7 +1451,7 @@ redef class AInternMethPropdef
                                v.add("printf({arguments.first}?\"true\\n\":\"false\\n\");")
                                return
                        else if pname == "object_id" then
-                               v.ret(arguments.first)
+                               v.ret(v.new_expr("(long){arguments.first}", ret.as(not null)))
                                return
                        else if pname == "==" then
                                v.ret(v.equal_test(arguments[0], arguments[1]))
@@ -1512,24 +1512,6 @@ redef class AInternMethPropdef
                                v.ret(v.new_expr("(long){arguments[0]}", ret.as(not null)))
                                return
                        end
-               else if cname == "Char" then
-                       if pname == "output" then
-                               v.add("printf(\"%c\", {arguments.first});")
-                               return
-                       else if pname == "object_id" then
-                               v.ret(arguments.first)
-                               return
-                       else if pname == "==" then
-                               v.ret(v.equal_test(arguments[0], arguments[1]))
-                               return
-                       else if pname == "!=" then
-                               var res = v.equal_test(arguments[0], arguments[1])
-                               v.ret(v.new_expr("!{res}", ret.as(not null)))
-                               return
-                       else if pname == "ascii" then
-                               v.ret(v.new_expr("{arguments[0]}", ret.as(not null)))
-                               return
-                       end
                else if cname == "NativeString" then
                        if pname == "[]" then
                                v.ret(v.new_expr("{arguments[0]}[{arguments[1]}]", ret.as(not null)))
diff --git a/tests/base_test_obj_id.nit b/tests/base_test_obj_id.nit
new file mode 100644 (file)
index 0000000..97c6c63
--- /dev/null
@@ -0,0 +1,30 @@
+# 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.
+
+intrude import string
+
+# Check Bool.object_id
+assert true.object_id.to_s.is_numeric
+
+# Check Int.object_id
+assert 3.object_id.to_s.is_numeric
+
+# Check Char.object_id
+assert 'd'.object_id.to_s.is_numeric
+
+# Check Float.object_id
+assert 1.0.object_id.to_s.is_numeric
+
+# Check NativeString.object_id
+assert "Test"._items.object_id.to_s.is_numeric
diff --git a/tests/sav/base_test_obj_id.res b/tests/sav/base_test_obj_id.res
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/sav/base_test_obj_id.sav b/tests/sav/base_test_obj_id.sav
new file mode 100644 (file)
index 0000000..e69de29