title: kotlin nested threads - "there is more than one label with such a name in this scope"
body: <p>I have some kotlin code similar to this:</p>
  
  <pre><code>Thread {
      ...
      Thread {
          ...
          return@Thread
          ...
      }.start()
      ...
  }.start()
  </code></pre>
  
  <p>Now I get the following warning:</p>
  
  <p><a href="https://i.stack.imgur.com/OKvtH.png" rel="noreferrer"><img src="https://i.stack.imgur.com/OKvtH.png" alt="enter image description here"></a></p>
  
  <p>I understand that kotlin is confused as to which Thread I want to return at this point, whether it's the outer or the inner thread. But I'm not sure how to tell it and Android Studio doesn't help much either, as it only suggests editing the options for this warning:</p>
  
  <p><a href="https://i.stack.imgur.com/m9Zhb.png" rel="noreferrer"><img src="https://i.stack.imgur.com/m9Zhb.png" alt="enter image description here"></a></p>
  
  <p>I have tried naming the thread and thought maybe kotlin is smart enough to check for that, but I guess this might not be possible, because the return label is probably not interpreted on runtime.</p>
  
  <p>I realize that I can just export the inner thread into a function and thereby have the threads not interfere with each other, like this:</p>
  
  <pre><code>Thread {
      ...
      startInnerThread()
      ...
  }.start()
  
  fun startInnerThread() {
      Thread {
          ...
          return@Thread
          ...
      }.start()
  }
  </code></pre>
  
  <p>But I would like to know if it's somehow possible to change the label <code>@Thread</code> for one of them instead.</p>