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 a73d1630d7fb358296b1860f42a7e688e0227339..1affdb393a1fd0c7eb653bada44aa8ba78ce89f5 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 c3e3ee014015f9dca26c83386d2265b0c686bd61..69a51571c41f298b060439b7061e463ee4d54dc4 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 0d8b326a796201ba6725be2f369da52e4e786c6f..36069c8bce2974bcdd794df5f161d7aee1daba8a 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 0000000000000000000000000000000000000000..040d76962e143d55c3fab1641b42c40ada6c5dc0 --- /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 0000000000000000000000000000000000000000..d5bc3014322c8ae183cbf5063b35c56085f3379b --- /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 0000000000000000000000000000000000000000..21e0f894291d9d04e741bc14b50a080a62fc78ae --- /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 0000000000000000000000000000000000000000..0b2523a798dca0b1d41334494aff07b5d929fd74 --- /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 0000000000000000000000000000000000000000..da15897fab5c29fa350ddbb876c6b94edfe44876 --- /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 0000000000000000000000000000000000000000..adb4873d768596701b92afc80042515629442ba1 --- /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 0000000000000000000000000000000000000000..bb2b5db25f938199f5c44f2fafa009a5dac09dff --- /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')