Really nice catch. And this points to a big thing I see in many beginners (albeit in reverse). Error attribution is hard when you’re learning a new language. In this case, the error is in Julia source, but you’re thinking your mental model is wrong. More frequently I see the reverse.
On this bug: I don’t believe it affects behavior, but it is now a missing optimization I think. It’d be awesome if you’d want to correct it! I think it should be written:
r =findfirst(splitter,str)
if r !== nothing
This mistake has been here for two years and has survived multiple touches from core devs. It probably wasn’t caught because it’s not going to trip any unit tests, and will only really show up as a performance issue if you have a really long string you’re splitting and the splitter isn’t found.
The sentinel value for search’s not found used to be 0:-1. Two separate API changes moved this to findfirst with a sentinel value of nothing, but those were both huge changes that touches many lines of code and required lots of menial fixes… so this one got missed.
And it passed in the first place because == falls back to === for disparate types, which seems like a bug-breeder. Is there a document providing the rationale for this fallback?
Amusingly enough, I stumbled across a comment (by myself) about this from last year while reviewing a separate PR. My initial assessment in this thread isn’t the whole story because findfirst("asdf", "") returns 1:0, so that branch actually is doing something in real code!