title: Swift: weird behavior of assertionFailure in release build
body: <p>In my opinion, <code>assertionFailure</code> will be ignored in release build. But when I run codes below in release mode, <code>assertionFailure</code> can run and stop the program. Why?</p>
  
  <p><em>Codes</em></p>
  
  <pre><code>enum MessageType: RawRepresentable {
      case news
      case unknownMessageType(value: String)
  
      init?(rawValue: String) {
          assertionFailure("Tihs assertionFailure will never stop execution")
          switch rawValue {
          case "A":
              self = .news
          case "B":
              self = .news
          case "C":
              self = .news
          case "D":
              self = .news
          case "E":
              self = .news
          case "F":
              self = .news
          case "G":
              self = .news
          case "H":
              self = .news
          case "I":
              self = .news
          case "J":
              self = .news
          case "K":
              self = .news
          case "L":
              self = .news
          case "M":
              self = .news
          case "N":
              self = .news
          case "O":
              self = .news
          case "P":
              self = .news
          case "Q":
              self = .news
          case "R":
              self = .news
          case "S":
              self = .news
          case "T":
              self = .news
          case "U":
              self = .news
          default:
              assertionFailure("This assertionFailure will cause a fatal error and stop execution")
              self = .unknownMessageType(value: rawValue)
          }
      }
  
      var rawValue: String {
          switch self {
          case .news:
              return "A"
          case .unknownMessageType(value: let value):
              return value
          }
      }
  }
  </code></pre>
  
  <p><strong>this statement will cause a crash</strong>
  <code>let message = MessageType(rawValue: "aaaa")</code>, caused by the second <code>assertionFailure</code> , not the first one.</p>
  
  <p><strong>Another weird thing is</strong> if I remove any two <code>case</code>(at least two <code>case</code>) in function <code>init?(rawValue: String)</code>, assertionFailure will be ignored, there will not be any crash.
  PS, I do not disable optimization for release build. </p>
  
  <p>Edit on 2018-11-29</p>
  
  <p>I posted a thread on <a href="https://forums.developer.apple.com/thread/111158" rel="nofollow noreferrer">Apple Developer Forum</a>, it seems like a compiler bug.</p>