I just had a bug in my program, but i don't understand how the program was compiled at all!
I have the following variable:
gamesPerCountriesMap: MutableMap<Long, MutableMap<Long, MutableList<AllScoresGameObj>>>?
and i had the following line of code:
var gamesList = gamesPerCountriesMap?.get(countryItem.id)?.get(competitionItem)
the correct line should be:
var gamesList = gamesPerCountriesMap?.get(countryItem.id)?.get(competitionItem.id)
i have looked at the prototype of the Map class and the method is declared as following:
public inline operator fun <@kotlin.internal.OnlyInputTypes K, V> Map<out K, V>.get(key: K): V?
As we can see it can get K and it's subtype, but competitionItem which is an instacne of class CompetitionObj isn't inherit the Long class. So why the compiler didn't prevent this error? I solved the issue but i am very couries of what is didn't prevent the code from being compiled?