My teachers in school always said that sugar tastes good because in the days of cavemen, things like berries, with lots of sugar, were rare, and it would be good to want to get the energy from them and thus humans evolved to like sugar. This BBC article also says something similar (emphasis mine):
Many scientists believe a child's preference for sweet things is an evolutionary hangover, as youngsters who preferred high-calorie foods in times gone by would have had a better chance of survival when food sources were unreliable.
This all makes sense to me. However, sometimes I eat something and it tastes too sweet. Why is this possible? It seems inconsistent with the way people evolved.