Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method registration fixes #476

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion R/generic.R
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,9 @@ generic_add_method <- function(generic, signature, method) {
p_tbl <- tbl
} else {
if (!is.null(p_tbl[[class_name]])) {
message("Overwriting method ", method_name(generic, signature))
if (!identical(p_tbl[[class_name]], method)) {
message("Overwriting method ", method_name(generic, signature))
}
}
p_tbl[[class_name]] <- method
}
Expand Down
4 changes: 2 additions & 2 deletions R/method-register.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ register_method <- function(generic,
# if we're inside a package, we also need to be able register methods
# when the package is loaded
if (!is.null(package) && !is_local_generic(generic, package)) {
generic <- as_external_generic(generic)
external_methods_add(package, generic, signature, method)
external_generic <- as_external_generic(generic)
external_methods_add(package, external_generic, signature, method)
}

invisible(generic)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/method-register.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Code
method(foo, class_character) <- (function(x) "c")
method(foo, class_character) <- (function(x) "c")
method(foo, class_character) <- (function(x) "d")
Message
Overwriting method foo(<character>)

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-method-register.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe("method registration", {
foo <- new_generic("foo", "x")
expect_snapshot({
method(foo, class_character) <- function(x) "c"
method(foo, class_character) <- function(x) "c"
method(foo, class_character) <- function(x) "d"
})
expect_length(methods(foo), 1)
})
Expand Down
Loading