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.

貢獻者指南