Commit e4a7da25
e4a7da259090Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 8 months ago · 2 files · ~2 modified
Description
Per-method origin_parser: fix 339 String#extend/Forwardable warnings
Methods from different required files now use their own parser for correct constant pool access during codegen. Previously, all methods in a reopened class shared the class's origin_parser, causing constant pool mismatch when methods came from different files.
method_info_t gains origin_parser field. emit_method swaps parser per-method instead of per-class.
865 → 585 warnings on lrama (280 reduction).
Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]
Details
- Commit
- e4a7da259090
- Parent
- 29bf764d2310
src/codegen.cmodifiedView file
@@ -344,6 +344,7 @@
344344
345345
m->body_node = def->body ? (pm_node_t *)def->body : NULL;346346
m->params_node = def->parameters ? (pm_node_t *)def->parameters : NULL;347+
m->origin_parser = ctx->parser;347348
m->param_count = 0;348349
m->is_getter = false;349350
m->is_setter = false;@@ -551,6 +552,7 @@
551552
free(name);552553
m->body_node = def->body ? (pm_node_t *)def->body : NULL;553554
m->params_node = def->parameters ? (pm_node_t *)def->parameters : NULL;555+
m->origin_parser = ctx->parser;554556
m->param_count = 0;555557
m->is_getter = false;556558
m->is_setter = false;@@ -2354,11 +2356,16 @@
23542356
for (int i = 0; i < ctx->class_count; i++) {23552357
class_info_t *cls = &ctx->classes[i];23562358
pm_parser_t *saved = ctx->parser;2357-
if (cls->origin_parser)2358-
ctx->parser = cls->origin_parser;2359-
for (int j = 0; j < cls->method_count; j++)2360-
emit_method(ctx, cls, &cls->methods[j]);2361-
ctx->parser = saved;2359+
for (int j = 0; j < cls->method_count; j++) {2360+
method_info_t *m = &cls->methods[j];2361+
/* Use method's own parser for correct constant pool access */2362+
if (m->origin_parser)2363+
ctx->parser = m->origin_parser;2364+
else if (cls->origin_parser)2365+
ctx->parser = cls->origin_parser;2366+
emit_method(ctx, cls, m);2367+
ctx->parser = saved;2368+
}23622369
}23632370
23642371
if (ctx->lambda_mode) {src/codegen.hmodifiedView file
Loading diff…