When calculating the weighted average cost of capital (WACC), it may be tempting to use the debt yield (yield to maturity, YTM) as the cost of debt. However, Berk & DeMarzo note in Chapter 12 of "Corporate Finance - 5th Global Edition" (see box "Common Mistake" on p. 454) that doing that would be a mistake. This is because the interest payments and the repayment of the principal are only promised, not actual. In case of a bankruptcy1, these payments may be reduced. Therefore, the actual cost of capital is lower than the interest rate on the loan.
This issue is minor to the point that it can be neglected for relatively safe debt (for sure if rated AAA or AA, mostly so if rated A and BBB, according to Table 12.2 on p. 454), but can become pretty significant for high-risk debt (BB and lower, ibid.).
In practice, how can we adjust YTM for the possibility of bankruptcy so that we obtain a fair estimate of the cost of debt? Does that have to be done on a case to case basis, drawing future scenarios of how much would be repaid under different circumstances and assigning probabilities to them? Or is there a simpler way?
1It does not always have to be bankruptcy, there can be more complicated cases, too.