Commit 671aab78
671aab78a460Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified
Description
Namespaced exception class in raise and rescue
raise M::Err / rescue M::Err now resolve the exception class by the final path component, matching how nested exception classes register. raise accepts a ConstantPathNode argument (with or without a message), and the rescue type test matches a ConstantPathNode clause by name.
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- 671aab78a460
- Parent
- 8d375f9fe756
src/codegen.cmodifiedView file
@@ -1471,10 +1471,12 @@
14711471
if (g_rescue_cls) buf_printf(b, "sp_raise_cls(%s, %s)", g_rescue_cls, g_rescue_msg);14721472
else buf_puts(b, "sp_raise((&(\"\\xff\")[1]))");14731473
}1474-
else if (ac == 1 && nt_type(nt, av[0]) && !strcmp(nt_type(nt, av[0]), "ConstantReadNode")) {1474+
else if (ac == 1 && nt_type(nt, av[0]) &&1475+
(!strcmp(nt_type(nt, av[0]), "ConstantReadNode") || !strcmp(nt_type(nt, av[0]), "ConstantPathNode"))) {14751476
buf_printf(b, "sp_raise_cls(\"%s\", (&(\"\\xff\")[1]))", nt_str(nt, av[0], "name"));14761477
}1477-
else if (ac >= 2 && nt_type(nt, av[0]) && !strcmp(nt_type(nt, av[0]), "ConstantReadNode")) {1478+
else if (ac >= 2 && nt_type(nt, av[0]) &&1479+
(!strcmp(nt_type(nt, av[0]), "ConstantReadNode") || !strcmp(nt_type(nt, av[0]), "ConstantPathNode"))) {14781480
buf_printf(b, "sp_raise_cls(\"%s\", ", nt_str(nt, av[0], "name"));14791481
emit_expr(c, av[1], b); buf_puts(b, ")");14801482
}@@ -5711,7 +5713,7 @@
57115713
int first = 1;57125714
for (int i = 0; i < nexc; i++) {57135715
const char *en = nt_type(nt, exc[i]);5714-
if (!en || strcmp(en, "ConstantReadNode")) continue;5716+
if (!en || (strcmp(en, "ConstantReadNode") && strcmp(en, "ConstantPathNode"))) continue;57155717
if (!first) buf_puts(b, " || ");57165718
first = 0;57175719
buf_printf(b, "sp_str_eq(_rcls_%d, \"%s\")", rc, nt_str(nt, exc[i], "name"));