From 999003c67ff13f87b4fa54dd2f6506dc471efd79 Mon Sep 17 00:00:00 2001
From: stepan <stepan.sindelar@oracle.com>
Date: Thu, 3 Nov 2016 16:03:07 +0100
Subject: [PATCH] Tests for NextMethod argument matching

---
 .../truffle/r/test/ExpectedTestOutput.test    | 329 ++++++++++++++++++
 .../com/oracle/truffle/r/test/TestRBase.java  |   2 +
 .../r/test/functions/S3/R/argMatching.R       |  21 ++
 .../r/test/functions/S3/R/nextMethod.R        |  36 ++
 .../S3/R/nextMethodAdditionalArgs1.R          |  32 ++
 .../S3/R/nextMethodAdditionalArgs2.R          |  41 +++
 .../S3/R/nextMethodAdditionalArgs3.R          |  40 +++
 .../S3/R/nextMethodAdditionalArgs4.R          |  34 ++
 .../S3/R/nextMethodAdditionalArgsPromises1.R  |  47 +++
 .../functions/S3/R/nextMethodArgsMatching.R   |  47 +++
 10 files changed, 629 insertions(+)
 create mode 100644 com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/functions/S3/R/nextMethod.R
 create mode 100644 com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/functions/S3/R/nextMethodAdditionalArgs1.R
 create mode 100644 com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/functions/S3/R/nextMethodAdditionalArgs2.R
 create mode 100644 com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/functions/S3/R/nextMethodAdditionalArgs3.R
 create mode 100644 com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/functions/S3/R/nextMethodAdditionalArgs4.R
 create mode 100644 com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/functions/S3/R/nextMethodAdditionalArgsPromises1.R
 create mode 100644 com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/functions/S3/R/nextMethodArgsMatching.R

diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test
index a73d1630d7..1affdb393a 100644
--- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test
+++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test
@@ -57620,6 +57620,335 @@ g.default args:
 NULL
 
 
+##com.oracle.truffle.r.test.functions.TestS3Dispatch.runRSourceTests#
+#{ source("mxbuild/com.oracle.truffle.r.test/bin/com/oracle/truffle/r/test/functions/S3/R/nextMethod.R") }
+called foo.default with  42
+with '' as class
+called foo.default with  42
+with classes baz and bar:
+called foo.baz with  42
+called foo.bar with  42
+
+##com.oracle.truffle.r.test.functions.TestS3Dispatch.runRSourceTests#
+#{ source("mxbuild/com.oracle.truffle.r.test/bin/com/oracle/truffle/r/test/functions/S3/R/nextMethodAdditionalArgs1.R") }
+called foo.baz with  42
+list()
+called foo.bar with  42
+[[1]]
+[1] 3
+
+
+##com.oracle.truffle.r.test.functions.TestS3Dispatch.runRSourceTests#
+#{ source("mxbuild/com.oracle.truffle.r.test/bin/com/oracle/truffle/r/test/functions/S3/R/nextMethodAdditionalArgs2.R") }
+foo.bar with:
+$x
+[1] 42
+attr(,"class")
+[1] "baz" "bar"
+
+$a
+[1] "caller-a"
+
+$b
+[1] "caller-b"
+
+$c
+[1] "explicit-from-baz"
+
+$cc
+[1] "caller-d"
+
+$named
+$named$e
+[1] "caller-e"
+
+$named$f
+[1] "named-from-baz"
+
+
+foo.bar with:
+$x
+[1] 42
+attr(,"class")
+[1] "bazz" "bar"
+
+$a
+[1] "caller-a"
+
+$b
+[1] "caller-b"
+
+$c
+[1] "explicit-from-baz"
+
+$cc
+[1] "caller-d"
+
+$named
+$named$e
+[1] "caller-e"
+
+$named$f
+[1] "named-from-baz"
+
+
+foo.bar with:
+$x
+[1] 42
+attr(,"class")
+[1] "bazzz" "bar"
+
+$a
+[1] "caller-a"
+
+$b
+[1] "caller-b"
+
+$c
+[1] "explicit-from-baz"
+
+$cc
+[1] "caller-d"
+
+$named
+$named$e
+[1] "caller-e"
+
+$named[[2]]
+[1] "matched-positionally?"
+
+$named$f
+[1] "named-from-baz"
+
+
+
+##com.oracle.truffle.r.test.functions.TestS3Dispatch.runRSourceTests#
+#{ source("mxbuild/com.oracle.truffle.r.test/bin/com/oracle/truffle/r/test/functions/S3/R/nextMethodAdditionalArgs3.R") }
+foo.baz
+foo.bar with:
+evaluated  b-from-caller
+$x
+[1] 42
+attr(,"class")
+[1] "baz" "bar"
+
+$a
+[1] "a-from-baz"
+
+$b
+[1] "b-from-caller"
+
+$named
+list()
+
+foo.bar with:
+evaluated  b-from-caller
+$x
+[1] 42
+attr(,"class")
+[1] "bazz" "bar"
+
+$a
+[1] "a-from-bazz"
+
+$b
+[1] "b-from-caller"
+
+$named
+list()
+
+foo.bar with:
+$x
+[1] 42
+attr(,"class")
+[1] "bazzz" "bar"
+
+$a
+[1] "a-from-bazz"
+
+$b
+[1] "b-from-caller"
+
+$named
+list()
+
+
+##com.oracle.truffle.r.test.functions.TestS3Dispatch.runRSourceTests#
+#{ source("mxbuild/com.oracle.truffle.r.test/bin/com/oracle/truffle/r/test/functions/S3/R/nextMethodAdditionalArgs4.R") }
+foo.baz
+foo.bar with:
+$x
+[1] 42
+attr(,"class")
+[1] "baz" "bar"
+
+$a
+[1] "positional-from-caller"
+
+$b
+[1] "positional-explicit"
+
+$mynamed
+[1] "named-explicit"
+
+
+##com.oracle.truffle.r.test.functions.TestS3Dispatch.runRSourceTests#Ignored.Unknown#
+#{ source("mxbuild/com.oracle.truffle.r.test/bin/com/oracle/truffle/r/test/functions/S3/R/nextMethodAdditionalArgsPromises1.R") }
+foo.bar with:
+$x
+[1] 42
+attr(,"class")
+[1] "baz" "bar"
+
+$a
+[1] "caller-a"
+
+$b
+[1] "caller-b"
+
+$c
+[1] "explicit-from-baz"
+
+$cc
+[1] "caller-d"
+
+$named
+$named$e
+[1] "caller-e"
+
+$named$f
+[1] "named-from-baz"
+
+
+foo.bar with:
+$x
+[1] 42
+attr(,"class")
+[1] "bazz" "bar"
+
+$a
+[1] "caller-a"
+
+$b
+[1] "caller-b"
+
+$c
+[1] "explicit-from-baz"
+
+$cc
+[1] "caller-d"
+
+$named
+$named$e
+[1] "caller-e"
+
+$named$f
+[1] "named-from-baz"
+
+
+foo.bar with:
+evaluated  matched-positionally?
+$x
+[1] 42
+attr(,"class")
+[1] "bazzz" "bar"
+
+$a
+[1] "caller-a"
+
+$b
+[1] "caller-b"
+
+$c
+[1] "explicit-from-baz"
+
+$cc
+[1] "caller-d"
+
+$named
+$named$e
+[1] "caller-e"
+
+$named[[2]]
+[1] "matched-positionally?"
+
+$named$f
+[1] "named-from-baz"
+
+
+
+##com.oracle.truffle.r.test.functions.TestS3Dispatch.runRSourceTests#
+#{ source("mxbuild/com.oracle.truffle.r.test/bin/com/oracle/truffle/r/test/functions/S3/R/nextMethodArgsMatching.R") }
+foo.bar with:
+$x
+[1] 42
+attr(,"class")
+[1] "baz" "bar"
+
+$a
+[1] "caller-a"
+
+$b
+[1] "caller-b"
+
+$c
+[1] "def-bar"
+
+$cc
+[1] "caller-d"
+
+$named
+$named$e
+[1] "caller-e"
+
+
+foo.bar with:
+$x
+[1] 42
+attr(,"class")
+[1] "bazz" "bar"
+
+$a
+[1] "caller-a"
+
+$b
+[1] "caller-b"
+
+$c
+[1] "def-bar"
+
+$cc
+[1] "caller-d"
+
+$named
+$named$e
+[1] "caller-e"
+
+
+foo.bar with:
+$x
+[1] 42
+attr(,"class")
+[1] "bazzz" "bar"
+
+$a
+[1] "caller-a"
+
+$b
+[1] "caller-b"
+
+$c
+[1] "def-bar"
+
+$cc
+[1] "caller-d"
+
+$named
+$named$e
+[1] "caller-e"
+
+
+
 ##com.oracle.truffle.r.test.functions.TestS3Dispatch.testComplexGroupDispatch#
 #{x<--7+2i;class(x)<-"foo";Complex.foo<-function(z){1;};Im(x);}
 [1] 1
diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/TestRBase.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/TestRBase.java
index c3e3ee0140..69a51571c4 100644
--- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/TestRBase.java
+++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/TestRBase.java
@@ -83,6 +83,8 @@ public class TestRBase extends TestBase {
                             testTrait = Output.IgnoreErrorContext;
                         } else if (l.contains("IgnoreWarningContext")) {
                             testTrait = Output.IgnoreWarningContext;
+                        } else if (l.contains("Ignored")) {
+                            testTrait = Ignored.Unknown;
                         }
                     }
                 }
diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/functions/S3/R/argMatching.R b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/functions/S3/R/argMatching.R
index 0d8b326a79..36069c8bce 100644
--- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/functions/S3/R/argMatching.R
+++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/functions/S3/R/argMatching.R
@@ -1,3 +1,24 @@
+# Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+
 g.default <- function(y,...) { cat('g.default args:\n'); print(list(if(missing(y)) NULL else y,...)); }
 g.c <- function(x,...) { cat('g.c args:\n'); print(list(if(missing(x)) NULL else x,...)); }
 g <- function(x,...) { cat('dispatch\n'); UseMethod('g') }
diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/functions/S3/R/nextMethod.R b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/functions/S3/R/nextMethod.R
new file mode 100644
index 0000000000..040d76962e
--- /dev/null
+++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/functions/S3/R/nextMethod.R
@@ -0,0 +1,36 @@
+# Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+
+foo <- function(x) UseMethod("foo")
+foo.default <- function(x) cat("called foo.default with ", x, "\n")
+foo.bar <- function(x) cat("called foo.bar with ", x, "\n")
+foo.baz <- function(x) { cat("called foo.baz with ", x, "\n"); NextMethod(unclass(x)); }
+
+val <- 42
+foo(val)
+
+cat("with '' as class\n")
+class(val) <- c('')
+foo(val)
+
+cat("with classes baz and bar:\n")
+class(val) <- c('baz', 'bar')
+foo(val)
\ No newline at end of file
diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/functions/S3/R/nextMethodAdditionalArgs1.R b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/functions/S3/R/nextMethodAdditionalArgs1.R
new file mode 100644
index 0000000000..d5bc301432
--- /dev/null
+++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/functions/S3/R/nextMethodAdditionalArgs1.R
@@ -0,0 +1,32 @@
+# Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+
+foo <- function(x, ...) UseMethod("foo")
+foo.default <- function(x, ...) { cat("called foo.default with ", x, "\n"); print(list(...)); }
+foo.bar <- function(x, ...) { cat("called foo.bar with ", x, "\n"); print(list(...)); }
+
+# in foo.baz NextMethod gets additional argument "3" that should be passed to foo.bar.
+# However, the first argument: vector of characters, is ignored
+foo.baz <- function(x, ...) { cat("called foo.baz with ", x, "\n"); print(list(...)); NextMethod(c('something', 'foo'), x, 3); }
+
+val <- 42
+class(val) <- c('baz', 'bar')
+foo(val)
\ No newline at end of file
diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/functions/S3/R/nextMethodAdditionalArgs2.R b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/functions/S3/R/nextMethodAdditionalArgs2.R
new file mode 100644
index 0000000000..21e0f89429
--- /dev/null
+++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/functions/S3/R/nextMethodAdditionalArgs2.R
@@ -0,0 +1,41 @@
+# Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+
+# tests the scenario when NextMethod has some additional arguments.
+# Note: it seems that those additional arguments are taken into account only
+# if named, otherwise the value is ignored (see 'matched-positionally?')
+# see also nextMethodArgsMatching.R
+
+withClass <- function(x, cls) { class(x) <- cls; x }
+
+foo <- function(x, ...) UseMethod("foo")
+foo.bar <- function(x, a, b, cc, c='def-bar', ...) {
+    cat("foo.bar with: \n");
+    print(list(x=x, a=a, b=b, c=c, cc=cc, named=list(...)))
+}
+
+foo.baz <-   function(x, d, a=1, c='def-baz', cc='def-cc-baz', ...) NextMethod(x, 'matched-positionally?', c='explicit-from-baz', f='named-from-baz')
+foo.bazz <-  function(x, d, a=1, c='def-baz', ...) NextMethod(c='explicit-from-baz', f='named-from-baz')
+foo.bazzz <- function(x, d, a=1, c='def-baz', ...) NextMethod('foo', x, 'matched-positionally?', c='explicit-from-baz', f='named-from-baz')
+
+foo(withClass(42, c('baz', 'bar')), 'caller-d', a='caller-a', b='caller-b', e='caller-e')
+foo(withClass(42, c('bazz', 'bar')), 'caller-d', a='caller-a', b='caller-b', e='caller-e')
+foo(withClass(42, c('bazzz', 'bar')), 'caller-d', a='caller-a', b='caller-b', e='caller-e')
diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/functions/S3/R/nextMethodAdditionalArgs3.R b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/functions/S3/R/nextMethodAdditionalArgs3.R
new file mode 100644
index 0000000000..0b2523a798
--- /dev/null
+++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/functions/S3/R/nextMethodAdditionalArgs3.R
@@ -0,0 +1,40 @@
+# Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+
+# tests the execution of promises when NextMethod has some additional arguments
+# that may override the original arguments. See also nextMethodArgsMatching.R
+
+withClass <- function(x, cls) { class(x) <- cls; x }
+side <- function(x) { cat("evaluated ", x, "\n"); x }
+
+foo <- function(x, ...) UseMethod("foo")
+foo.bar <- function(x, a, b, ...) {
+    cat("foo.bar with: \n");
+    print(list(x=x, a=a, b=b, named=list(...)))
+}
+
+foo.baz <-   function(x, ...) { cat("foo.baz\n"); NextMethod(x, a='a-from-baz') }
+foo.bazz <-  function(x, a, b, ...) NextMethod(x, a='a-from-bazz')
+foo.bazzz <-  function(x, a='a-default', b, ...) NextMethod(x, a='a-from-bazz')
+
+foo(withClass(42, c('baz', 'bar')), a=side('a-from-caller'), b=side('b-from-caller'))
+foo(withClass(42, c('bazz', 'bar')), a=side('a-from-caller'), b=side('b-from-caller'))
+foo(withClass(42, c('bazzz', 'bar')), b='b-from-caller')
diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/functions/S3/R/nextMethodAdditionalArgs4.R b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/functions/S3/R/nextMethodAdditionalArgs4.R
new file mode 100644
index 0000000000..da15897fab
--- /dev/null
+++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/functions/S3/R/nextMethodAdditionalArgs4.R
@@ -0,0 +1,34 @@
+# Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+
+# Tests the scenario when NextMethod has some additional arguments.
+# Tests the overriding of arguments passed to S3 dispatch method (foo) by explicit arguments given to NextMethod.
+
+withClass <- function(x, cls) { class(x) <- cls; x }
+
+foo <- function(x, ...) UseMethod("foo")
+foo.bar <- function(x, a, b, mynamed) {
+    cat("foo.bar with: \n");
+    print(list(x=x, a=a, b=b, mynamed=mynamed))
+}
+foo.baz <- function(x, ...) { cat("foo.baz\n"); NextMethod('foo', x, 'positional-explicit', mynamed='named-explicit') }
+
+foo(withClass(42, c('baz', 'bar')), 'positional-from-caller', mynamed='named-from-caller')
diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/functions/S3/R/nextMethodAdditionalArgsPromises1.R b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/functions/S3/R/nextMethodAdditionalArgsPromises1.R
new file mode 100644
index 0000000000..adb4873d76
--- /dev/null
+++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/functions/S3/R/nextMethodAdditionalArgsPromises1.R
@@ -0,0 +1,47 @@
+# Ignored
+# Note: once this works, we can remove nextMethodAdditionalArgs2.R,
+# which is the same test without promises evaluation check
+
+# Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+
+# tests the scenario when NextMethod has some additional arguments.
+# Note: it seems that those additional arguments are taken into account only
+# if named, otherwise the value is ignored (see 'matched-positionally?')
+# see also nextMethodArgsMatching.R
+
+withClass <- function(x, cls) { class(x) <- cls; x }
+
+side <- function(x) { cat("evaluated ", x, "\n"); x }
+
+foo <- function(x, ...) UseMethod("foo")
+foo.bar <- function(x, a, b, cc, c='def-bar', ...) {
+    cat("foo.bar with: \n");
+    print(list(x=x, a=a, b=b, c=c, cc=cc, named=list(...)))
+}
+
+foo.baz <-   function(x, d, a=1, c='def-baz', cc='def-cc-baz', ...) NextMethod(x, side('matched-positionally?'), c='explicit-from-baz', f='named-from-baz')
+foo.bazz <-  function(x, d, a=1, c='def-baz', ...) NextMethod(c='explicit-from-baz', f='named-from-baz')
+foo.bazzz <- function(x, d, a=1, c='def-baz', ...) NextMethod('foo', x, side('matched-positionally?'), c='explicit-from-baz', f='named-from-baz')
+
+foo(withClass(42, c('baz', 'bar')), 'caller-d', a='caller-a', b='caller-b', e='caller-e')
+foo(withClass(42, c('bazz', 'bar')), 'caller-d', a='caller-a', b='caller-b', e='caller-e')
+foo(withClass(42, c('bazzz', 'bar')), 'caller-d', a='caller-a', b='caller-b', e='caller-e')
diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/functions/S3/R/nextMethodArgsMatching.R b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/functions/S3/R/nextMethodArgsMatching.R
new file mode 100644
index 0000000000..bb2b5db25f
--- /dev/null
+++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/functions/S3/R/nextMethodArgsMatching.R
@@ -0,0 +1,47 @@
+# Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+
+# tests that the signature of the call of the S3 dispatch function is matched to
+# the signature of the target of NextMethod. Note that default value of 'c' in
+# foo.baz is ignored and 'cc' in foo.bar is matched positionally with 'caller-d'.
+
+withClass <- function(x, cls) { class(x) <- cls; x }
+
+# a - matched by name param
+# b - unmatched named param, but matched named in foo.bar
+# c - default param (no value given), default (no value given) in foo.bar
+# cc - default param (no value given), not default default in foo.bar
+# d - matched positional param
+# e - unmatched named param, stays unmatched named in foo.bar
+
+foo <- function(x, ...) UseMethod("foo")
+foo.bar <- function(x, a, b, cc, c='def-bar', ...) {
+    cat("foo.bar with: \n");
+    print(list(x=x, a=a, b=b, c=c, cc=cc, named=list(...)))
+}
+
+foo.baz <-   function(x, d, a=1, c='def-baz', cc='def-cc-baz', ...) NextMethod(x)
+foo.bazz <-  function(x, d, a=1, c='def-baz', ...) NextMethod()
+foo.bazzz <- function(x, d, a=1, c='def-baz', ...) NextMethod('foo')
+
+foo(withClass(42, c('baz', 'bar')), 'caller-d', a='caller-a', b='caller-b', e='caller-e')
+foo(withClass(42, c('bazz', 'bar')), 'caller-d', a='caller-a', b='caller-b', e='caller-e')
+foo(withClass(42, c('bazzz', 'bar')), 'caller-d', a='caller-a', b='caller-b', e='caller-e')
-- 
GitLab