I have not been able to make a testcase for this, but this should be safe, and
it may fix the assertion being hit in https://reviews.llvm.org/D151630#4378572.
(We should absolutely figure out a testcase for this, either before or after
this is checked in.)
Drive-by nit. .has_value()should only be in unit tests. The .has_value() is redundant in this case.