title: Kotlin generics fail when deduced from lambda argument
body: <p>Today I encountered strange behavior while creating some Kotlin generics. Code below illustrates the problem.</p>
  
  <p><strong>MCVE</strong></p>
  
  <pre><code>class Generic&lt;T&gt;(private val initial: T? = null, private val source: (T)-&gt;Unit) {
      fun test(value: T) = source(value)
  }
  
  fun &lt;T&gt; createGeneric(initial: T? = null, source: (T)-&gt;Unit) = Generic(initial, source)
  
  fun test() {
      val generic = createGeneric(null) { arg: Int -&gt; println(arg) }
      generic.test(42) 
  }
  </code></pre>
  
  <p>The line <code>generic.test(42)</code> produces error: </p>
  
  <blockquote>
    <p>The integral literal does not conform to the expected type Nothing</p>
  </blockquote>
  
  <p>Question: How can <code>T</code> be deduced as <code>Nothing</code>, since I pass <code>{ arg: Int -&gt; println(arg) }</code> lambda, which is <code>(Int)-&gt;Unit</code>?. I double-checked type of variable <code>generic</code>, and it's deduced as <code>Generic&lt;Nothing&gt;</code>. </p>
  
  <p>Also, if the type is deduced as <code>Nothing</code>, why it allows to pass lambda of type <code>(Int)-&gt;Unit</code> as second argument?</p>
  
  <p><a href="https://pl.kotl.in/WZ0-ig-Nf" rel="nofollow noreferrer">Kotlin Playground Example</a></p>