bilateral_trade: all-zero trade group returns an unnamed matrix, violating the documented name-indexing contract
#235 opened on 2026/07/22
Repository metrics
- Stars
- (1 個のスター)
- PR merge metrics
- (PR metrics pending)
説明
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.