Adjust logic to properly sort erlang versions

Fixes #21417.