Getting "Conflicting overloads" for every function in one Kotlin file whenever I change it

Viewed 7027

For one Kotlin file in my project, almost every time I make changes to it and rebuild, I get "Conflicting overload" messages for every function. There aren't two conflicting functions; each error message lists exactly the same function twice. If I do a clean build, it builds fine.

e: ContentApi.kt: (220, 1): Conflicting overloads: public fun loadExclusions(assetIds: List): Unit defined in com.foo.bar in file ContentApi.kt, public fun loadExclusions(assetIds: List): Unit defined in com.foo.bar in file ContentApi.kt

Changes to other Kotlin files don't produce the same problem. I can create a function in another Kotlin file, build with no trouble, then cut and paste it into this file, and boom.

Has anyone else seen something like this? My best guess is that it's some kind of bug with the compiled code cache where the newly compiled code doesn't replace the previous version, so they conflict with each other.

Android Studio/Gradle version 3.2 RC 3 Kotlin version 1.2.61

2 Answers

This is normally happening, when you have two functions with the same names but different annotations.

For Example:

@PrePersist
public fun loadExclusions(assetIds: List){
}

@PreUpdate
public fun loadExclusions(assetIds: List){
}

I had the same and the problem was that I have changed package from main folder to location like debugger suggested on the beginning (before I changed all locations). When I left original package inside it was ok.

Related