eduaguilera/whep

bilateral_trade: all-zero trade group returns an unnamed matrix, violating the documented name-indexing contract

Aberta

#235 aberto em 22 de jul. de 2026

 (1 comentário) (0 reação) (0 responsável)R (3 forks)auto 404
area:tradebuggood first issuehelp wantedmechanicalno-data-neededpriority:low

Métricas do repositório

Stars
 (1 estrela)
Métricas de merge de PR
 (Métricas PR pendentes)

Description

What

In the trade-matrix builder (R/bilateral_trade.R:158-160), when sum(exports)==0 && sum(imports)==0 the function returns matrix(0, n, n) with no dimnames, whereas every other path sets dimnames. The docstring promises m["A","B"] name indexing.

Why it matters

Benign today only by accident: both consumers short-circuit on zero content (melt_one_trade_matrix returns NULL when no nonzero cells; .extract_trade_matrix falls through to a zero matrix). It is a latent contract violation that breaks the moment a consumer name-indexes an all-zero group before checking content.

Suggested fix / check

Set dimnames on the zero-matrix path too, consistent with the other return paths.


From deep static audit (2026-07-23), round 2, parallel subsystem review. Deduplicated against open+closed issues. Not verified by running unless stated.

Guia do colaborador