Skip to content

Commit 4ad1d2c

Browse files
author
maechler
committed
amending r87971 for simple as(.,.)
git-svn-id: https://svn.r-project.org/R/trunk@88019 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent d38b36a commit 4ad1d2c

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

src/library/methods/R/MethodsListClass.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# File src/library/methods/R/MethodsListClass.R
22
# Part of the R package, https://www.R-project.org
33
#
4-
# Copyright (C) 1995-2024 The R Core Team
4+
# Copyright (C) 1995-2025 The R Core Team
55
#
66
# This program is free software; you can redistribute it and/or modify
77
# it under the terms of the GNU General Public License as published by
@@ -123,9 +123,10 @@ loadMethod <- function(method, fname, envir) method
123123
setGeneric("loadMethod", where = envir)
124124
setMethod("loadMethod", "MethodDefinition",
125125
function(method, fname, envir) {
126-
assign(".target", method@target, envir = envir)
126+
assign(".target", method@target, envir = envir)
127127
assign(".defined", method@defined, envir = envir)
128-
assign(".Method", method, envir = envir)
128+
assign(".Generic", method@generic, envir = envir)
129+
assign(".Method", method, envir = envir)
129130
method
130131
}, where = envir)
131132
setMethod("loadMethod", "MethodWithNext",

src/library/methods/R/as.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ as <-
9393
}
9494
environment(asMethod) <- asMethodEnv <- new.env(parent = environment(asMethod))
9595
loadMethod(asMethod, envir = asMethodEnv)
96-
assign(".Generic", asMethod@generic, envir = asMethodEnv)
9796
if(strict)
9897
asMethod(object)
9998
else

tests/classes-methods.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,16 @@ stopifnot( is(m0, "MethodDefinition"),
208208
is(m1, "MethodDefinitionWithTrace"),
209209
identical(m0, m2), identical(a0, a1))
210210

211+
## Checking that "simple" as() still works:
212+
setClass("A", slots = c(x = "NULL"))
213+
setClass("B", slots = c(x = "NULL"))
214+
setIs("A", "B",
215+
test = function(.) { TRUE },
216+
coerce = function(.) new("B"),
217+
replace = function(., value) new("B"))
218+
B <- as(new("A"), "B") ## gave Error in asMethod@generic : ... `@` applied to ... "function"
219+
stopifnot(identical(B, new("B")))
220+
211221

212222

213223
cat('Time elapsed: ', proc.time(),'\n')

0 commit comments

Comments
 (0)