Fix RT #77114.

Straight up stolen from STD.pm6, these modifications pass the tests pushed in [this roast commit](https://github.com/perl6/roast/commit/3f00b5b12c6526ca2af4da2140896373408ea099).