Uploaded image for project: 'Swift'
  1. Swift
  2. SR-14552

SwiftSyntax crashes when parsing a malformed function type

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Done
    • Component/s: SwiftSyntax
    • Labels:
      None

      Description

      This is a repro of a case that recently started failing in one of swift-format's tests against the main branch (I'm using the 2021-04-26 development snapshot as my current environment).

      When parsing the following source code:

          let x: (A -> B)

      (Note that "A" should have its own parentheses surrounding it for this to be valid.)

      The parser crashes with the following message:

      Assertion failed: (isValid() && "length does not make sense for an invalid range"), function getByteLength, file /Users/buildnode/jenkins/workspace/oss-swift-package-macos/swift/include/swift/Basic/SourceLoc.h, line 218.

      I would expect this to fail in some other, non-crashing fashion, such as expressing the syntax using Unknown* nodes.

      To reproduce:

      1. Download the attached project.
      2. Use a development toolchain that is syntax-compatible with swift-syntax's main branch (at the time I'm writing this, 2021-04-26 worked).
      3. Run swift run TriviaCrash.

        Attachments

          Activity

            People

            Assignee:
            ahoppen Alex Hoppen
            Reporter:
            allevato Tony Allevato
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: