nitc/transform: maintain vararg information when transforming expressions
authorJean Privat <jean@pryen.org>
Thu, 24 Mar 2016 23:29:00 +0000 (19:29 -0400)
committerJean Privat <jean@pryen.org>
Thu, 24 Mar 2016 23:29:39 +0000 (19:29 -0400)
close #1971

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

src/transform.nit
tests/base_vararg_transform.nit [new file with mode: 0644]
tests/sav/base_vararg_transform.res [new file with mode: 0644]

index 010a944..3e5865b 100644 (file)
@@ -117,6 +117,7 @@ redef class AExpr
                super
                if other isa AExpr then
                        if other.implicit_cast_to == null then other.implicit_cast_to = implicit_cast_to
+                       other.vararg_decl = vararg_decl
                end
        end
 end
diff --git a/tests/base_vararg_transform.nit b/tests/base_vararg_transform.nit
new file mode 100644 (file)
index 0000000..732da49
--- /dev/null
@@ -0,0 +1,27 @@
+# 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.
+
+fun foo(i: Object...) do print i
+
+var n: nullable Object = null
+
+foo(1, 1)
+
+foo((false or true) and true, 2)
+foo(n or else 1, 3)
+foo(if true then 1 else -1, 4)
+
+foo([1..3], 5)
+foo([1,2,3], 6)
+foo([for i in [0..2] do i + 1], 7)
diff --git a/tests/sav/base_vararg_transform.res b/tests/sav/base_vararg_transform.res
new file mode 100644 (file)
index 0000000..12a875f
--- /dev/null
@@ -0,0 +1,7 @@
+[1,1]
+[true,2]
+[1,3]
+[1,4]
+[[1,2,3],5]
+[[1,2,3],6]
+[[1,2,3],7]