Skip to content
Open
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: 2 additions & 2 deletions R/type-asis.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ vec_proxy.AsIs <- function(x, ...) {

#' @export
vec_restore.AsIs <- function(x, to, ...) {
asis_restore(x)
asis_restore(NextMethod())
}

#' @export
Expand Down Expand Up @@ -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
}
10 changes: 10 additions & 0 deletions tests/testthat/test-type-asis.R
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down