diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/CallMatcherNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/CallMatcherNode.java index fa01f31ea9879cd1422a07ccad89f66df1d9a40a..a27af4e3c7d1df84c2dba2f2573b1b3c7dd85b6e 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/CallMatcherNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/CallMatcherNode.java @@ -4,7 +4,7 @@ * http://www.gnu.org/licenses/gpl-2.0.html * * Copyright (c) 2014, Purdue University - * Copyright (c) 2014, 2017, Oracle and/or its affiliates + * Copyright (c) 2014, 2018, Oracle and/or its affiliates * * All rights reserved. */ @@ -343,9 +343,15 @@ public abstract class CallMatcherNode extends RBaseNode { RCaller parent = RArguments.getCall(frame).getParent(); String genFunctionName = functionName == null ? function.getName() : functionName; - RCaller caller = genFunctionName == null ? RCaller.createInvalid(frame, parent) - : RCaller.create(frame, RCallerHelper.createFromArguments(genFunctionName, - new RArgsValuesAndNames(reorderedArgs.getArguments(), ArgumentsSignature.empty(reorderedArgs.getLength())))); + + RCaller caller; + if (genFunctionName == null) { + caller = RCaller.createInvalid(frame, parent); + } else { + Supplier<RSyntaxElement> argsSupplier = RCallerHelper.createFromArguments(genFunctionName, new RArgsValuesAndNames(suppliedArguments, suppliedSignature)); + caller = RCaller.create(frame, parent, argsSupplier); + } + MaterializedFrame callerFrame = (dispatchArgs instanceof S3Args) ? ((S3Args) dispatchArgs).callEnv : null; try { return call.execute(frame, function, caller, callerFrame, reorderedArgs.getArguments(), reorderedArgs.getSignature(), function.getEnclosingFrame(), dispatchArgs); diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/RCallerHelper.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/RCallerHelper.java index 4b1a0f0af8a824d2e17135a6688db029ba97ef4d..0962add7cd7196c5abd483388d58d0b323c10e46 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/RCallerHelper.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/RCallerHelper.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2018, 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 @@ -66,7 +66,7 @@ public final class RCallerHelper { return createFromArgumentsInternal(function, arguments); } - public static Supplier<RSyntaxElement> createFromArgumentsInternal(final Object function, final RArgsValuesAndNames arguments) { + private static Supplier<RSyntaxElement> createFromArgumentsInternal(final Object function, final RArgsValuesAndNames arguments) { return new Supplier<RSyntaxElement>() { RSyntaxElement syntaxNode = null; 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 e4c5f5ed012f7ab0b344b7e4e75bf29b4b67ebe8..51789f4ee66e413efe6427c9d17ba981f39a45f2 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 @@ -39069,6 +39069,14 @@ cat(... = pairlist("abc", p = 3, lab = "b"), sep = ..1, fill = 13) #fn3 <- function(...) { (function(...) match.call(cat, call("cat", "abc", p=3,as.symbol("...")), expand.dots = TRUE))(...) }; fn3(sep=x,lab="b",fill=13) cat("abc", p = 3, lab = "b", sep = ..1, fill = 13) +##com.oracle.truffle.r.test.builtins.TestBuiltin_matchcall.testMatchCall# +#{ f <- function(a, ...) { UseMethod('f1', a) };f1.default <- function(a, b=2, c=3, d=4, e=5, ...) { match.call() };f(a=1); f(a=1, b=2); f(a=1, b=2, c=3);f(a=1, b=2, d=4);f(a=1, c=3, d=4, e=5) } +f1.default(a = 1, c = 3, d = 4, e = 5) + +##com.oracle.truffle.r.test.builtins.TestBuiltin_matchcall.testMatchCall# +#{ f <- function(a, b, c, d, e) { UseMethod('f1', a) };f1.default <- function(a, b=2, c=3, d=4, e=5) { match.call() };f(a=1); f(a=1, b=2); f(a=1, b=2, c=3);f(a=1, b=2, d=4);f(a=1, c=3, d=4, e=5) } +f1.default(a = 1, c = 3, d = 4, e = 5) + ##com.oracle.truffle.r.test.builtins.TestBuiltin_matchcall.testMatchCall# #{ f1<-function(...) { dots <- match.call(expand.dots = FALSE)$...; dots }; f2<-function(...) f1(...); f2("a") } [[1]] @@ -40700,7 +40708,7 @@ In mean.default(x = c(2L, 1L, 2L, 2L)) : #argv <- structure(list(x = structure(1412795929.08562, class = c('POSIXct', 'POSIXt'))), .Names = 'x');do.call('mean.POSIXct', argv) [1] "2014-10-08 19:18:49 GMT" -##com.oracle.truffle.r.test.builtins.TestBuiltin_meandefault.testmeandefault1#Output.IgnoreWarningContext# +##com.oracle.truffle.r.test.builtins.TestBuiltin_meandefault.testmeandefault1# #argv <- structure(list(x = structure(c(2L, 1L, 2L, 2L), .Label = c('FALSE', 'TRUE'), class = 'factor')), .Names = 'x');do.call('mean.default', argv) [1] NA Warning message: diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_matchcall.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_matchcall.java index 1b61c42d86967398bf3267c0815e8d8d0436dc9c..934b455fa4cee3e623ab424f58f4f1e20a94a625 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_matchcall.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_matchcall.java @@ -4,7 +4,7 @@ * http://www.gnu.org/licenses/gpl-2.0.html * * Copyright (c) 2012-2014, Purdue University - * Copyright (c) 2013, 2016, Oracle and/or its affiliates + * Copyright (c) 2013, 2018, Oracle and/or its affiliates * * All rights reserved. */ @@ -78,6 +78,20 @@ public class TestBuiltin_matchcall extends TestBase { assertEval("{ foo<-function(...) match.call(expand.dots=F); bar<-function(x) x; y<-42; foo(bar(y), 7) }"); + assertEval("{ f <- function(a, ...) { UseMethod('f1', a) };" + + "f1.default <- function(a, b=2, c=3, d=4, e=5, ...) { match.call() };" + + // fill up signature cache + "f(a=1); f(a=1, b=2); f(a=1, b=2, c=3);f(a=1, b=2, d=4);" + + // this should be ok as well + "f(a=1, c=3, d=4, e=5) }"); + + assertEval("{ f <- function(a, b, c, d, e) { UseMethod('f1', a) };" + + "f1.default <- function(a, b=2, c=3, d=4, e=5) { match.call() };" + + // fill up signature cache + "f(a=1); f(a=1, b=2); f(a=1, b=2, c=3);f(a=1, b=2, d=4);" + + // this should be ok as well + "f(a=1, c=3, d=4, e=5) }"); + // TODO add tests that pass "definition" and "call" explicitly } diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_meandefault.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_meandefault.java index dddae6feba6b33f225111fbc7b8958ec3a5f8d0c..ccb984ffad1186c8e5a429cc47abec8e72ee660a 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_meandefault.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_meandefault.java @@ -4,7 +4,7 @@ * http://www.gnu.org/licenses/gpl-2.0.html * * Copyright (c) 2014, Purdue University - * Copyright (c) 2014, 2016, Oracle and/or its affiliates + * Copyright (c) 2014, 2018, Oracle and/or its affiliates * * All rights reserved. */ @@ -20,7 +20,6 @@ public class TestBuiltin_meandefault extends TestBase { @Test public void testmeandefault1() { - assertEval(Output.IgnoreWarningContext, - "argv <- structure(list(x = structure(c(2L, 1L, 2L, 2L), .Label = c('FALSE', 'TRUE'), class = 'factor')), .Names = 'x');do.call('mean.default', argv)"); + assertEval("argv <- structure(list(x = structure(c(2L, 1L, 2L, 2L), .Label = c('FALSE', 'TRUE'), class = 'factor')), .Names = 'x');do.call('mean.default', argv)"); } }