Skip to content

Commit

Permalink
Fix valgrind issue (#1094)
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley authored Aug 1, 2023
1 parent 9d38049 commit 110b22f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# purrr (development version)

* Fixed valgrind issue.

* Deprecation infrastructure in `map_chr()` now has much less overhead
leading to improved performance (#1089).

Expand Down
25 changes: 24 additions & 1 deletion src/coerce.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,34 @@
#include "conditions.h"

void cant_coerce(SEXP from, SEXP to, int i) {

const char* to_friendly;
switch(TYPEOF(to)) {
case INTSXP:
to_friendly = "an integer";
break;
case REALSXP:
to_friendly = "a double";
break;
case STRSXP:
to_friendly = "a string";
break;
case LGLSXP:
to_friendly = "a logical";
break;
case RAWSXP:
to_friendly = "a raw vector";
break;
default:
to_friendly = Rf_type2char(TYPEOF(to));
}


Rf_errorcall(
R_NilValue,
"Can't coerce from %s to %s.",
rlang_obj_type_friendly_full(from, false, false),
rlang_obj_type_friendly_full(to, false, false)
to_friendly
);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/map.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
Error in `map_int()`:
i In index: 3.
Caused by error:
! Can't coerce from a string to an integer vector.
! Can't coerce from a string to an integer.
Code
map(1:3, ~ fail_at_3(.x, stop("Doesn't work")))
Condition
Expand Down

0 comments on commit 110b22f

Please sign in to comment.