summaryrefslogtreecommitdiff
path: root/eval_error.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-10-28 06:24:12 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-10-28 06:24:12 +0000
commit72ff61f4a8ae7a8bf05b0bd6f91b3b290645627c (patch)
tree731069832b17cffaafc9fdcdd394f1976c7ec576 /eval_error.c
parent7a929727f6a4e45a0ebf0542650ff122b16264ad (diff)
NameError#receiver of uninitialized constant
* error.c (name_err_mesg_to_str): quote the name if unprintable. * object.c (check_setter_id): use rb_check_id to convert names. * variable.c (uninitialized_constant): use NameError::message to keep the receiver of uninitialized constant. [Feature #10881] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52321 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'eval_error.c')
-rw-r--r--eval_error.c60
1 files changed, 33 insertions, 27 deletions
diff --git a/eval_error.c b/eval_error.c
index e907d7ee88..82a69033b6 100644
--- a/eval_error.c
+++ b/eval_error.c
@@ -208,47 +208,53 @@ ruby_error_print(void)
error_print();
}
-static const char *
-method_visibility_name(rb_method_visibility_t visi)
-{
- switch (visi) {
- case METHOD_VISI_UNDEF:
- case METHOD_VISI_PUBLIC: return "";
- case METHOD_VISI_PRIVATE: return " private";
- case METHOD_VISI_PROTECTED: return " protected";
- }
- rb_bug("method_visibility_name: unreachable (%d)", (int)visi);
-}
+#define undef_mesg_for(v, k) rb_fstring_cstr("undefined"v" method `%1$s' for "k" `%$s'")
+#define undef_mesg(v) ( \
+ is_mod ? \
+ undef_mesg_for(v, "module") : \
+ undef_mesg_for(v, "class"))
void
rb_print_undef(VALUE klass, ID id, int visi)
{
- const char *v = method_visibility_name(visi);
-
- rb_name_error(id, "undefined%s method `%"PRIsVALUE"' for %s `% "PRIsVALUE"'", v,
- QUOTE_ID(id),
- (RB_TYPE_P(klass, T_MODULE)) ? "module" : "class",
- rb_class_name(klass));
+ const int is_mod = RB_TYPE_P(klass, T_MODULE);
+ VALUE mesg;
+ switch (visi & METHOD_VISI_MASK) {
+ case METHOD_VISI_UNDEF:
+ case METHOD_VISI_PUBLIC: mesg = undef_mesg(""); break;
+ case METHOD_VISI_PRIVATE: mesg = undef_mesg(" private"); break;
+ case METHOD_VISI_PROTECTED: mesg = undef_mesg(" protected"); break;
+ default: UNREACHABLE;
+ }
+ rb_name_err_raise_str(mesg, klass, ID2SYM(id));
}
void
rb_print_undef_str(VALUE klass, VALUE name)
{
- rb_name_error_str(name, "undefined method `%"PRIsVALUE"' for %s `% "PRIsVALUE"'",
- QUOTE(name),
- (RB_TYPE_P(klass, T_MODULE)) ? "module" : "class",
- rb_class_name(klass));
+ const int is_mod = RB_TYPE_P(klass, T_MODULE);
+ rb_name_err_raise_str(undef_mesg(""), klass, name);
}
+#define inaccessible_mesg_for(v, k) rb_fstring_cstr("method `%1$s' for "k" `%2$s' is "v)
+#define inaccessible_mesg(v) ( \
+ is_mod ? \
+ inaccessible_mesg_for(v, "module") : \
+ inaccessible_mesg_for(v, "class"))
+
void
rb_print_inaccessible(VALUE klass, ID id, rb_method_visibility_t visi)
{
- const char *v = method_visibility_name(visi);
- rb_name_error(id, "method `%"PRIsVALUE"' for %s `% "PRIsVALUE"' is %s",
- QUOTE_ID(id),
- (RB_TYPE_P(klass, T_MODULE)) ? "module" : "class",
- rb_class_name(klass),
- v);
+ const int is_mod = RB_TYPE_P(klass, T_MODULE);
+ VALUE mesg;
+ switch (visi & METHOD_VISI_MASK) {
+ case METHOD_VISI_UNDEF:
+ case METHOD_VISI_PUBLIC: mesg = inaccessible_mesg(""); break;
+ case METHOD_VISI_PRIVATE: mesg = inaccessible_mesg(" private"); break;
+ case METHOD_VISI_PROTECTED: mesg = inaccessible_mesg(" protected"); break;
+ default: UNREACHABLE;
+ }
+ rb_name_err_raise_str(mesg, klass, ID2SYM(id));
}
static int