Skip to content

Commit

Permalink
A comment for typed data in rb_check_type [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed Aug 14, 2021
1 parent d58620e commit edd27e1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 8 additions & 0 deletions error.c
Expand Up @@ -1007,6 +1007,14 @@ rb_check_type(VALUE x, int t)

xt = TYPE(x);
if (xt != t || (xt == T_DATA && RTYPEDDATA_P(x))) {
/*
* Typed data is not simple `T_DATA`, but in a sense an
* extension of `struct RVALUE`, which are incompatible with
* each other except when inherited.
*
* So it is not enough to just check `T_DATA`, it must be
* identified by its `type` using `Check_TypedStruct` instead.
*/
unexpected_type(x, xt, t);
}
}
Expand Down
4 changes: 1 addition & 3 deletions include/ruby/internal/value_type.h
Expand Up @@ -340,9 +340,7 @@ Check_Type(VALUE v, enum ruby_value_type t)
goto unexpected_type;
}
else if (t == RUBY_T_DATA && rbimpl_rtypeddata_p(v)) {
/* The intention itself is not necessarily clear to me, but at least it
* is intentional to rule out typed data here. See commit
* a7c32bf81d3391cfb78cfda278f469717d0fb794. */
/* Typed data is not simple `T_DATA`, see `rb_check_type` */
goto unexpected_type;
}
else {
Expand Down

0 comments on commit edd27e1

Please sign in to comment.