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

Comments not followed by whitespace can confuse compiler

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Done
    • Component/s: Compiler
    • Labels:
    • Environment:

      Swift 2.1.1, Xcode 7.2

      Description

      Attempting to compile the following:

      let even = false
      
      if /* some comment */!even {
          print("odd")
      }
      

      Fails with the following errors:

      error: expected expression, var, or let in 'if' condition
                      if /* some comment */!even {
                                           ^
      error: braced block of statements is an unused closure
                      if /* some comment */!even {
                                                 ^
      error: expression resolves to an unused function
                      if /* some comment */!even {
      

      Adding whitespace between the */ and ! compiles fine:

      if /* some comment */ !even {
      

      As does removing the NOT without added whitespace:

      if /* some comment */even {
      

      Expectation: I would expect the compiler to treat everything between and including the /* */ delimiters to be treated as invisible such that:

      if /* some comment */!even {
      

      would appear to the compiler as

      if !even {
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              jder Jesse Rusak
              Reporter:
              somegeekintn Casey Fleser
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: