title: Kotlin contracts: link not-null of two properties
body: <p>Say I have a class like this:</p>
  
  <pre><code>data class URLAndPath(
     val baseUrl: URL,
     val path: String?
  ) {
      val url get(): URL? =
          try { path?.let { URL(baseUrl, it) } }
          catch(_: Exception) { null }
  
      init { require(path == null || url != null) { "Invalid URL $baseUrl$path" } } 
  }
  </code></pre>
  
  <p>This class ensures that if <code>path != null</code> if and only if <code>url != null</code></p>
  
  <p><a href="https://github.com/Kotlin/KEEP/blob/master/proposals/kotlin-contracts.md" rel="nofollow noreferrer">Kotlin contracts</a> seems the way to tell the compiler about these kinds of relations. Is the above invariant possible to model with Kotlin contracts?</p>
  
  <p>My end result is to let code like the following compile:</p>
  
  <pre><code>val x = URLAndPath(URL("http://example.org/"), "index.html")
  if(x.path != null) {
      // currently: Error: Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type URL?
      println(x.url.toURI())
  }
  </code></pre>