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

'foo bar' could have fixit suggesting missing . rather than just ; or ,

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Medium
    • Resolution: Unresolved
    • Component/s: Compiler
    • Labels:
    • Environment:

      Master at 2018-08-09

      Description

      For instance, in the following code, the mistake is missing the ., not missing a ;

      struct Foo {
          var bar = 0
      }
      
      let foo = Foo()
      
      let something = 1 + foo bar 
      foo bar = 1
      print(foo bar)
      

      The errors for each of the three invalid lines are:

      space.swift:7:24: error: consecutive statements on a line must be separated by ';'
      let something = 1 + foo bar 
                             ^
                             ;
      space.swift:7:19: error: binary operator '+' cannot be applied to operands of type 'Int' and 'Foo'
      let something = 1 + foo bar 
                      ~ ^ ~~~
      space.swift:7:19: note: expected an argument list of type '(Int, Int)'
      let something = 1 + foo bar 
                        ^
      space.swift:7:25: error: use of unresolved identifier 'bar'
      let something = 1 + foo bar 
                              ^~~
      
      space.swift:8:4: error: consecutive statements on a line must be separated by ';'
      foo bar = 1
         ^
         ;
      space.swift:8:1: warning: expression of type 'Foo' is unused
      foo bar = 1
      ^~~
      space.swift:8:5: error: use of unresolved identifier 'bar'
      foo bar = 1
          ^~~
      
      space.swift:9:11: error: expected ',' separator
      print(foo bar)
                ^
               ,
      space.swift:9:11: error: use of unresolved identifier 'bar'
      print(foo bar)
                ^~~
      

      If it looks like an property access (or even a method call) might be valid (i.e. the thing after the space is an identifier), the compiler could guess at using . rather than/as well as ; or ,.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              huon Huon Wilson
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: