diff --git a/R/type-asis.R b/R/type-asis.R index 8ba2b967b..06f905490 100644 --- a/R/type-asis.R +++ b/R/type-asis.R @@ -35,7 +35,7 @@ vec_proxy.AsIs <- function(x, ...) { #' @export vec_restore.AsIs <- function(x, to, ...) { - asis_restore(x) + asis_restore(NextMethod()) } #' @export @@ -115,6 +115,6 @@ asis_strip <- function(x) { asis_restore <- function(x) { # Using `oldClass()` here to return `NULL` for atomics # so that their implicit class isn't added - class(x) <- c("AsIs", oldClass(x)) + class(x) <- unique.default(c("AsIs", oldClass(x))) x } diff --git a/tests/testthat/test-type-asis.R b/tests/testthat/test-type-asis.R index 27da09688..d132c5961 100644 --- a/tests/testthat/test-type-asis.R +++ b/tests/testthat/test-type-asis.R @@ -50,6 +50,16 @@ test_that("order proxy is forwarded correctly for atomic types (#1557)", { expect_identical(vec_proxy_order(asis), c(1L, 2L, 1L)) }) +test_that("proxy is restored correctly for non-atomic types (#1903)", { + x <- new_rcrd(list(x = 1:3, y = 2:4), class = "test") + x_ptype <- new_rcrd(list(x = integer(), y = integer()), class = "test") + asis <- I(x) + asis_ptype <- I(x_ptype) + + expect_identical(vec_restore(vec_proxy(asis), asis_ptype), I(vec_restore(vec_proxy(x), x_ptype))) + expect_identical(vec_restore(vec_proxy(asis), asis_ptype), asis) +}) + # ------------------------------------------------------------------------------ # Coercion