Merge: Fix calls on primitive receivers
authorJean Privat <jean@pryen.org>
Fri, 8 May 2015 02:11:21 +0000 (22:11 -0400)
committerJean Privat <jean@pryen.org>
Fri, 8 May 2015 02:11:21 +0000 (22:11 -0400)
Fix #1301

Pull-Request: #1318
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>

src/compiler/separate_compiler.nit
tests/base_primitive_recv.nit [new file with mode: 0644]
tests/sav/base_primitive_recv.res [new file with mode: 0644]

index 34e7be4..3e7fbcb 100644 (file)
@@ -1436,13 +1436,14 @@ class SeparateCompilerVisitor
                if compiler.modelbuilder.toolcontext.opt_invocation_metrics.value then add("count_invoke_by_tables++;")
 
                assert arguments.length == mmethod.intro.msignature.arity + 1 else debug("Invalid arity for {mmethod}. {arguments.length} arguments given.")
-               var recv = arguments.first
 
                var res0 = before_send(mmethod, arguments)
 
                var runtime_function = mmethod.intro.virtual_runtime_function
                var msignature = runtime_function.called_signature
 
+               adapt_signature(mmethod.intro, arguments)
+
                var res: nullable RuntimeVariable
                var ret = msignature.return_mtype
                if ret == null then
@@ -1451,18 +1452,7 @@ class SeparateCompilerVisitor
                        res = self.new_var(ret)
                end
 
-               var ss = new FlatBuffer
-
-               ss.append("{recv}")
-               for i in [0..msignature.arity[ do
-                       var a = arguments[i+1]
-                       var t = msignature.mparameters[i].mtype
-                       if i == msignature.vararg_rank then
-                               t = arguments[i+1].mcasttype
-                       end
-                       a = self.autobox(a, t)
-                       ss.append(", {a}")
-               end
+               var ss = arguments.join(", ")
 
                var const_color = mentity.const_color
                var ress
diff --git a/tests/base_primitive_recv.nit b/tests/base_primitive_recv.nit
new file mode 100644 (file)
index 0000000..a409bd5
--- /dev/null
@@ -0,0 +1,39 @@
+# 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.
+
+import standard::kernel
+
+
+redef class Int
+       fun foo do self.output
+end
+
+fun bar(i: nullable Int) do i.foo
+
+redef class Float
+       fun foo do self.output
+end
+
+fun baz(i: nullable Float) do i.foo
+
+bar(1)
+baz(1.0)
+
+var a: nullable Object
+
+a = 1
+a.foo
+
+a = 1.0
+a.foo
diff --git a/tests/sav/base_primitive_recv.res b/tests/sav/base_primitive_recv.res
new file mode 100644 (file)
index 0000000..f70f395
--- /dev/null
@@ -0,0 +1,4 @@
+1
+1.000000
+1
+1.000000