One possible explanation is that you do
alias done='something'
prior to sourcing /usr/share/bash-completion/bash_completion.
That would explain that error message as bash would complain about the function being closed while the while loop hasn't (because of the missing done that was replaced by something).
Don't use done or any shell keyword as an alias name (though you could define some instrumenting aliases like alias do='do ((loop_level++));'; alias done='((loop_level--)); done' as long as they keep the shell structure).