Uploaded image for project: 'SonarSwift'
  1. SonarSwift
  2. SONARSWIFT-112

Parse Error: "where" clause (GUARD_CLAUSE) can appear in condition

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.2
    • Component/s: Parser
    • Labels:
      None

      Description

      if let x = a where b {
      }
      

      From Xcode 6.3 release notes https://developer.apple.com/library/ios/releasenotes/DeveloperTools/RN-Xcode/Chapters/xc6_release_notes.html#//apple_ref/doc/uid/TP40001051-CH4-SW6

      The if–let construct has been expanded to allow testing multiple optionals and guarding conditions in a single if (or while) statement using syntax similar to generic constraints:

      if let a = foo(), b = bar() where a < b,
         let c = baz() {
      }
      

      This allows you to test multiple optionals and include intervening boolean conditions, without introducing undesirable nesting (for instance, to avoid the optional unwrapping “pyramid of doom”).
      Further, if–let now also supports a single leading boolean condition along with optional binding let clauses. For example:

      if someValue > 42 && someOtherThing < 19,          let a = getOptionalThing() where a > someValue {
      }
      

      (19797158), (19382942)
      The if–let syntax has been extended to support a single leading boolean condition along with optional binding let clauses.
      For example:

      if someValue > 42 && someOtherThing < 19,          let a = getOptionalThing() where a > someValue {
      }
      

      New grammar of condition (since Swift 1.2) should be implemented (same for if-condition)

      while-condition -> expression­ | expression­ opt­ optional-binding-list­
      optional-binding-list -> optional-binding-clause­ | optional-binding-clause­,­ optional-binding-list­
      optional-binding-clause -> optional-binding-head ­optional-binding-continuation-list­ opt­ guard-clause­ opt­
      optional-binding-head -> let­ identifier-pattern ­initializer­ | var ­identifier-pattern ­initializer­
      optional-binding-continuation-list -> optional-binding-continuation­ | optional-binding-continuation­,­ optional-binding-continuation-list­
      optional-binding-continuation -> identifier-pattern ­initializer­ | optional-binding-head­

        Attachments

          Activity

            People

            Assignee:
            elena.vilchik Elena Vilchik
            Reporter:
            elena.vilchik Elena Vilchik
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: