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

Fix parsing error for function with implicit return of closure expression

    XMLWordPrintable

    Details

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

      Description

      Reproducer which fail to parse:

      func fun() -> () -> Int { { return 42 } }
      

      which is equivalent to:

      func fun() -> () -> Int { return { return 42 } }
      

      From https://docs.swift.org/swift-book/LanguageGuide/Functions.html:

      Functions With an Implicit Return
      If the entire body of the function is a single expression, the function implicitly returns that expression.

      This parsing error was caused by disambiguation introduced by SONARSWIFT-11, it should be safe to allow code blocks with single element being a closure expression.

        Attachments

          Activity

            People

            Assignee:
            massimo.paladin Massimo PALADIN
            Reporter:
            massimo.paladin Massimo PALADIN
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Due:
              Created:
              Updated:
              Resolved: