I had this BUG! exception in phase 'semantic analysis' in source unit '...'
issue today and upgrading gradle (as mentioned in a comment) didn’t work.
What worked for me was cleaning the gradle cache:
rm -rf $HOME/.gradle/caches/
and project gradle directory
rm -rf $PROJECT/.gradle/caches/ && rm -rf $PROJECT/build/