Skip to content

vec_c() and list_unchop() report bad error message for incompatible fallback objects in the >=3rd position #1981

@DavisVaughan

Description

@DavisVaughan
library(vctrs)

foobar <- function(x) {
  structure(x, class = "vctrs_foobar")
}

# Works
vec_c(
  foobar(1:2), foobar(5L)
)
#> [1] 1 2 5
#> attr(,"class")
#> [1] "vctrs_foobar"

# Correctly fails, good error
#
# This is a failure because `typeof` isn't the same between
# the two fallback objects
vec_c(
  foobar(1:2), foobar(0)
)
#> Error in `vec_c()`:
#> ! Can't combine `..1` <vctrs_foobar> and `..2` <vctrs_foobar>.
#> ✖ Some attributes are incompatible.
#> ℹ The author of the class should implement vctrs methods.
#> ℹ See <https://vctrs.r-lib.org/reference/faq-error-incompatible-attributes.html>.

# Correctly fails, bad error
#
# Common type of the first 2 is a `vctrs:::common_class_fallback`,
# and the common type of that and `foobar(5)` results in a failure,
# but the failure doesn't remove the `vctrs:::common_class_fallback`
# class in the failure report
vec_c(
  foobar(1:2), foobar(5L), foobar(0)
)
#> Error in `vec_c()`:
#> ! Can't combine `..1` <vctrs:::common_class_fallback> and `..3` <vctrs_foobar>.

# This also affects `list_unchop()`'s `default` argument, so we should
# add a test for that too
list_unchop(
  x = list(foobar(1:2), foobar(5:6)),
  indices = list(1:2, 5:6),
  size = 7,
  default = foobar(0)
)
#> Error in `list_unchop()`:
#> ! Can't combine <vctrs:::common_class_fallback> and `default` <vctrs_foobar>.

Created on 2025-07-15 with reprex v2.1.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions