Fix #5051

Sorry for the delay, I thought I might combine this with solving https://github.com/JuliaLang/julia/issues/5068, but since i just used the function referred to in https://github.com/JuliaLang/julia/issues/5051#issuecomment-3006196, there was no reason to wait.