diff --git a/R/generic.R b/R/generic.R index bdea8145..a4a262c2 100644 --- a/R/generic.R +++ b/R/generic.R @@ -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 } diff --git a/R/method-register.R b/R/method-register.R index 6f35d1cf..6f6f9cab 100644 --- a/R/method-register.R +++ b/R/method-register.R @@ -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) diff --git a/tests/testthat/_snaps/method-register.md b/tests/testthat/_snaps/method-register.md index 9953586f..0354114e 100644 --- a/tests/testthat/_snaps/method-register.md +++ b/tests/testthat/_snaps/method-register.md @@ -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() diff --git a/tests/testthat/test-method-register.R b/tests/testthat/test-method-register.R index 66d3715d..5d6547e1 100644 --- a/tests/testthat/test-method-register.R +++ b/tests/testthat/test-method-register.R @@ -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) })