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

Previously unknown syntax is now parsed as AttributedTypeSyntax; not sure if expected

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Won't Do
    • Component/s: SwiftSyntax
    • Labels:
      None

      Description

      In swift-format, we were using the following code snippet to test how we handled syntax trees that contained Unknown*Syntax nodes:

          @unknown foo class Bar {}

      At some point fairly recently in main (I'm using the 2021-04-26 development snapshot), the parser behavior changed and it now parses this as valid; the result is two CodeBlockItems:

      1. a TypeExpr containing the AttributedType @unknown foo
      2. the ClassDecl class Bar {}

      Something similar happens with a malformed @unknown default:

          switch a {
          case x: break
          @unknown foo default: break
      {{    }}}

      This body of case x is parsed as two CodeBlockItems (break, then @unknown foo), and then the next SwitchCase starts at the default.

      Are these changes expected?

      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 UnknownAttr.
      4. Observe the tree output.

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            allevato Tony Allevato
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: