
can override scalar vector error message for base scalar types
==============================================================

> vec_ptype2(NULL, quote(x), y_arg = "foo")
Error: `foo` must be a vector, not a symbol.

> vec_ptype2(quote(x), NULL, x_arg = "foo")
Error: `foo` must be a vector, not a symbol.


can override scalar vector error message for S3 types
=====================================================

> vec_ptype2(NULL, foobar(), y_arg = "foo")
Error: `foo` must be a vector, not a `vctrs_foobar` object.

> vec_ptype2(foobar(), NULL, x_arg = "foo")
Error: `foo` must be a vector, not a `vctrs_foobar` object.


ptype2 and cast errors when same class fallback is impossible are informative
=============================================================================

> vec_cast(foobar(1, bar = TRUE), foobar(2, baz = TRUE))
Error: Can't convert <vctrs_foobar> to <vctrs_foobar>.
x Some attributes are incompatible.
i The author of the class should implement vctrs methods.
i See <https://vctrs.r-lib.org/reference/faq-error-incompatible-attributes.html>.

> vec_ptype2(foobar(1, bar = TRUE), foobar(2, baz = TRUE))
Error: Can't combine <vctrs_foobar> and <vctrs_foobar>.
x Some attributes are incompatible.
i The author of the class should implement vctrs methods.
i See <https://vctrs.r-lib.org/reference/faq-error-incompatible-attributes.html>.

> # Incompatible attributes bullets are not show when methods are implemented
> with_foobar_cast <- (function(expr) {
+   with_methods(vec_cast.vctrs_foobar = function(...) NULL,
+   vec_cast.vctrs_foobar.vctrs_foobar = function(x, to, ...) vec_default_cast(x,
+     to, ...), expr)
+ })
> with_foobar_ptype2 <- (function(expr) {
+   with_methods(vec_ptype2.vctrs_foobar = function(...) NULL,
+   vec_ptype2.vctrs_foobar.vctrs_foobar = function(x, y, ...) vec_default_ptype2(
+     x, y, ...), expr)
+ })
> with_foobar_cast(vec_cast(foobar(1, bar = TRUE), foobar(2, baz = TRUE)))
Error: Can't convert <vctrs_foobar> to <vctrs_foobar>.

> with_foobar_ptype2(vec_ptype2(foobar(1, bar = TRUE), foobar(2, baz = TRUE)))
Error: Can't combine <vctrs_foobar> and <vctrs_foobar>.


common type errors don't mention columns if they are compatible
===============================================================

> df <- data.frame(x = 1, y = "")
> foo <- structure(df, class = c("vctrs_foo", "data.frame"))
> bar <- structure(df, class = c("vctrs_bar", "data.frame"))
> vec_cast_no_fallback(foo, bar)
Error: Can't convert <vctrs_foo> to <vctrs_bar>.


common type warnings for data frames take attributes into account
=================================================================

> foobar_bud <- foobar(mtcars, bud = TRUE)
> foobar_boo <- foobar(mtcars, boo = TRUE)
> vec_ptype2_fallback(foobar_bud, foobar_boo)
Warning: Can't combine <vctrs_foobar> and <vctrs_foobar>; falling back to <data.frame>.
x Some attributes are incompatible.
i The author of the class should implement vctrs methods.
i See <https://vctrs.r-lib.org/reference/faq-error-incompatible-attributes.html>.

 [1] mpg  cyl  disp hp   drat wt   qsec vs   am   gear carb
<0 rows> (or 0-length row.names)

> # For reference, warning for incompatible classes
> vec_ptype2_fallback(foobar(mtcars), foobaz(mtcars))
Warning: Can't combine <vctrs_foobar> and <vctrs_foobaz>; falling back to <data.frame>.

 [1] mpg  cyl  disp hp   drat wt   qsec vs   am   gear carb
<0 rows> (or 0-length row.names)

> # For reference, error when fallback is disabled
> vec_ptype2_no_fallback(foobar(mtcars), foobaz(mtcars))
Error: Can't combine <vctrs_foobar> and <vctrs_foobaz>.

