Commit ff32fc29

ff32fc295cc5Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified

Description

codegen: fix _new forward declaration parameter mismatch

When initialize takes parameters, the forward declaration for sp_Cls_new was always emitted as static sp_Cls_new() (no params), but the actual definition used the initialize params. GCC rejects the conflicting types.

Generate the forward declaration with the correct parameter types, matching the emit_class_new logic. Also use void for zero-param constructors to be precise.

Co-Authored-By: Claude Sonnet 4.6 [email protected]

Details

Commit
ff32fc295cc5
Parent
b578174c6c6a

src/codegen.cmodifiedView file

@@ -7438,7 +7438,21 @@
74387438 if (ci->nivars == 0) buf_puts(&b, "void");
74397439 buf_puts(&b, ");\n");
74407440 }
7441- else buf_printf(&b, "static sp_%s *sp_%s_new();\n", ci->name, ci->name);
7441+ else {
7442+ int icid = i;
7443+ int init = comp_method_in_chain(c, i, "initialize", &icid);
7444+ if (init >= 0 && c->scopes[init].nparams > 0) {
7445+ buf_printf(&b, "static sp_%s *sp_%s_new(", ci->name, ci->name);
7446+ Scope *s = &c->scopes[init];
7447+ for (int m = 0; m < s->nparams; m++) {
7448+ if (m) buf_puts(&b, ", ");
7449+ LocalVar *p = scope_local(s, s->pnames[m]);
7450+ emit_ctype(c, p ? p->type : TY_INT, &b);
7451+ }
7452+ buf_puts(&b, ");\n");
7453+ }
7454+ else buf_printf(&b, "static sp_%s *sp_%s_new(void);\n", ci->name, ci->name);
7455+ }
74427456 }
74437457 if (c->nscopes > 1 || c->nclasses > 0) buf_puts(&b, "\n");
74447458