JetBrains/kotlin — pull request #282 by lopekpl (2013-05-29 18:23:35+00:00)
Title: Type mismatch in literals3

Continuation of https://github.com/JetBrains/kotlin/pull/271.

I fixed the issues you pointed, except for one:

> Do you think that quick fix should be available for this case or it's a bug?
> ```val a: Int = if (true) "" /*here: Change 'a' type to 'String' */ else 1```
> It woulld be nice if it suggest to Change 'a' type to 'Any' (as a common supertype of Int and String)

same issue: ```fun foo(): Int = if (true) "" else 1```
or: ```fun foo(): Int { return if (true) "" else 1 }```

My genaral idea was to look for a type of the *if* expression in binding context, but in this case (Int + String) recorded type of expression is *Comparable\* which is wrong (because parameter of comparable is invariant). Fixing it was not straightforward for me, so I eventually couldn't make up my mind what to do with this issue and ended up doing nothing.

If you agree:
1) I would leave this as it is now (well, it does not behave well, but I believe it's also not a misbehavior)
2) Go back to this issue as soon as I'm finished with this, and one more PR that I'm involved in (which is a lot shorter than this one). Next week.

Btw I created an issue that is related to the problem I faced: http://youtrack.jetbrains.com/issue/KT-3660