title: Avoid Infinite recursion with Swift Operator Definitions?
body: <p>I'm following along with a Tic Tac Toe swift tutorial here: <a href="https://www.youtube.com/watch?v=LkYpoRj-7hA" rel="nofollow">https://www.youtube.com/watch?v=LkYpoRj-7hA</a>.</p>
  
  <p>I've been making changes to the code as I progress such as creating structs and enums to better structure the entities in the code. I wanted to create an equality operator for two optional Structs called "Player." This operator would return false if either argument was nil or if their "kind" fields weren't equal (kinds are an enum). Here is the code I wrote to do this:</p>
  
  <pre><code>1.  @infix func == ( left: Player?, right: Player? ) -&gt; Bool
  2.  {
  3.     var isEqual = false
  4.
  5.     if( left? == nil || right? == nil )
  6.     {
  7.         isEqual = false
  8.     }
  9.
  10.    if( left!.kind == right!.kind )
  11.    {
  12.         isEqual = true
  13.    }
  14.
  15.    return isEqual
  16. }
  </code></pre>
  
  <p>The problem is that I believe it's being called recursively on itself when I check for nil (line 5). It crashes at runtime with the call stack listing this function over and over.</p>
  
  <p>Questions: Is my hypothesis that this is triggering infinite recursion correct? If so is this a bug in Swift or is this how it ought to work? Is there a way to check for equality with nil without the function calling itself?</p>