backported changes from ruby’s error.c to type checks
Backported new stuff from ruby.h