Skip to content

Commit 72868a7

Browse files
committed
[GR-22669] Fix S3 dispatch with missing argument
(cherry picked from commit ec20f94)
1 parent 1ca6934 commit 72868a7

File tree

5 files changed

+103
-2
lines changed

5 files changed

+103
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ New features:
2525

2626
Bug fixes:
2727

28+
* S3 dispatch with missing arguments, e.g., `as_tibble()` (reported by Michael Hall on Slack)
2829
* `dyn.load` did not work with relative paths
2930
* missing warnings on integer overflow #136
3031
* the f2c script fixed to handle extra dotted file extensions #143

com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/S3DispatchFunctions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1515
*
1616
* Copyright (c) 2014, Purdue University
17-
* Copyright (c) 2014, 2019, Oracle and/or its affiliates
17+
* Copyright (c) 2014, 2020, Oracle and/or its affiliates
1818
*
1919
* All rights reserved.
2020
*/
@@ -241,7 +241,7 @@ private static Object getFirstNonMissingArg(VirtualFrame frame, int startIdx) {
241241
}
242242

243243
private static Object getFirstVarArg(RArgsValuesAndNames varArgs) {
244-
return varArgs.isEmpty() ? null : varArgs.getArgument(0);
244+
return varArgs.isEmpty() ? RNull.instance : varArgs.getArgument(0);
245245
}
246246
}
247247

com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95111,6 +95111,56 @@ NULL
9511195111
foo.c1
9511295112
foo.c1
9511395113

95114+
##com.oracle.truffle.r.test.functions.TestS3Dispatch.runRSourceTests#
95115+
#{ source("tmptest/S3/missingAsNULL1.R") }
95116+
[[1]]
95117+
[[1]]$overload
95118+
[1] "NULL"
95119+
95120+
[[1]]$x_missing
95121+
[1] TRUE
95122+
95123+
[[1]]$args
95124+
list()
95125+
95126+
95127+
[[2]]
95128+
[[2]]$overload
95129+
[1] "NULL"
95130+
95131+
[[2]]$x_missing
95132+
[1] FALSE
95133+
95134+
[[2]]$args
95135+
list()
95136+
95137+
95138+
95139+
##com.oracle.truffle.r.test.functions.TestS3Dispatch.runRSourceTests#
95140+
#{ source("tmptest/S3/missingAsNULL2.R") }
95141+
$first_missing
95142+
$first_missing$overload
95143+
[1] "bar"
95144+
95145+
$first_missing$x_missing
95146+
[1] TRUE
95147+
95148+
$first_missing$y_missing
95149+
[1] FALSE
95150+
95151+
95152+
$all_missing
95153+
$all_missing$overload
95154+
[1] "bar"
95155+
95156+
$all_missing$x_missing
95157+
[1] TRUE
95158+
95159+
$all_missing$y_missing
95160+
[1] TRUE
95161+
95162+
95163+
9511495164
##com.oracle.truffle.r.test.functions.TestS3Dispatch.runRSourceTests#
9511595165
#{ source("tmptest/S3/nextMethod.R") }
9511695166
called foo.default with 42
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright (c) 2020, 2020, Oracle and/or its affiliates. All rights reserved.
2+
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3+
#
4+
# This code is free software; you can redistribute it and/or modify it
5+
# under the terms of the GNU General Public License version 3 only, as
6+
# published by the Free Software Foundation.
7+
#
8+
# This code is distributed in the hope that it will be useful, but WITHOUT
9+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11+
# version 3 for more details (a copy is included in the LICENSE file that
12+
# accompanied this code).
13+
#
14+
# You should have received a copy of the GNU General Public License version
15+
# 3 along with this work; if not, write to the Free Software Foundation,
16+
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17+
#
18+
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
19+
# or visit www.oracle.com if you need additional information or have any
20+
# questions.
21+
22+
foo <- function(x, ..., abc = 'default_value') UseMethod('foo')
23+
foo.NULL <- function(x, ..., abc) list(overload = "NULL", x_missing = missing(x), args = list(...))
24+
print(list(foo(), foo(NULL)))
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright (c) 2020, 2020, Oracle and/or its affiliates. All rights reserved.
2+
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3+
#
4+
# This code is free software; you can redistribute it and/or modify it
5+
# under the terms of the GNU General Public License version 3 only, as
6+
# published by the Free Software Foundation.
7+
#
8+
# This code is distributed in the hope that it will be useful, but WITHOUT
9+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11+
# version 3 for more details (a copy is included in the LICENSE file that
12+
# accompanied this code).
13+
#
14+
# You should have received a copy of the GNU General Public License version
15+
# 3 along with this work; if not, write to the Free Software Foundation,
16+
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17+
#
18+
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
19+
# or visit www.oracle.com if you need additional information or have any
20+
# questions.
21+
22+
foo <- function(x, y, z) UseMethod('foo')
23+
foo.NULL <- function(x, y, z) list(overload = "bar", x_missing = missing(x), y_missing = missing(y))
24+
foo.bar <- function(x, y, z) list(overload = "bar", x_missing = missing(x), y_missing = missing(y))
25+
indirect <- function(...) foo(...)
26+
print(list(first_missing = indirect(y=structure(33, class='bar')), all_missing = indirect()))

0 commit comments

Comments
 (0)