Skip to content

Commit 9f8edb2

Browse files
committed
Fix PHP trait flattening when trait matches class name
1 parent b075f05 commit 9f8edb2

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

‎internal/cbm/lsp/php_lsp.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3434,14 +3434,17 @@ static void flatten_trait_into_class(PHPLSPContext *ctx, CBMTypeRegistry *reg, c
34343434
if (!t)
34353435
t = lookup_type_with_project(ctx, trait_qn);
34363436
const char *canonical_trait_qn = t ? t->qualified_name : trait_qn;
3437+
if (strcmp(canonical_trait_qn, class_qn) == 0)
3438+
return;
34373439

34383440
/* Iterate registry funcs whose receiver_type is the trait.
34393441
*
34403442
* Self-substitution: when the trait's method has a return type that
34413443
* names the trait itself (e.g. `tap(): self` registered as
34423444
* NAMED(trait_qn)), rewrite it to NAMED(using_class_qn) so chains
34433445
* like `$c->tap()->classMethod()` resolve correctly. */
3444-
for (int i = 0; i < reg->func_count; i++) {
3446+
int func_count = reg->func_count;
3447+
for (int i = 0; i < func_count; i++) {
34453448
const CBMRegisteredFunc *src = &reg->funcs[i];
34463449
if (!src->receiver_type || strcmp(src->receiver_type, canonical_trait_qn) != 0) {
34473450
continue;

0 commit comments

Comments
 (0)