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

Improve compiler error with a fix-it: Cannot assign to value, 'bar' is a 'let' constant

    XMLWordPrintable

    Details

      Description

      struct Foo {
          private var bar : Int
          
          init(bar: Int) {
              bar = bar
          }
      }
      
      error: <stdin>:3:13: error: cannot assign to value: 'bar' is a 'let' constant
      

      New developers are puzzled by this. Obviously, they should have written this instead:

      self.bar = bar
      

      I think it would be a better experience if this was transformed into a fix-it, where we would offer the chance to append "self." to the LHS.

        Attachments

        1. Screen Shot 2017-10-17 at 8.54.19 PM.png
          1.25 MB
          Mayur Dhaka
        2. Screen Shot 2017-10-17 at 8.54.26 PM.png
          1.31 MB
          Mayur Dhaka
        3. Screen Shot 2017-10-17 at 9.02.15 PM.png
          894 kB
          Mayur Dhaka

          Activity

            People

            Assignee:
            greg Greg Titus
            Reporter:
            jrose Jordan Rose
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: