eduaguilera/whep

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

开放

#235 创建于 2026年7月22日

 (1 条评论) (0 个反应) (0 位负责人)R (3 个派生)auto 404
area:tradebuggood first issuehelp wantedmechanicalno-data-neededpriority:low

仓库指标

星标
 (1 个星标)
PR 合并指标
 (PR 指标待抓取)

描述

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.

贡献者指南