Why do I get a type mismatch when attempting to return a value for a checked generic parameter?
<p>In the following code <code>"Happy Halloween!"</code>, <code>42</code>, etc. are flagged as "Type mismatch." (Required: T, Found: String (or Int)) but shouldn't the compiler be able to infer that the return value is of the correct type from the type check?</p>

<pre><code>interface Type&lt;T&gt;
class StringType() : Type&lt;String&gt;
class IntType1() : Type&lt;Int&gt;
class IntType2(val a: Int, val b: Int) : Type&lt;Int&gt;

fun &lt;T&gt; something(type: Type&lt;T&gt;): T = when (type) {
    is StringType -&gt; "Happy Halloween!"
    is IntType1 -&gt; 42
    is IntType2 -&gt; type.a * type.a + type.b * type.b + type.a * type.b
    else -&gt; throw IllegalArgumentException()
}
</code></pre>