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

Improved diagnostics when using instance methods before initialization

    XMLWordPrintable

    Details

      Description

      One of the most common errors beginners of Swift like me make is to start using class instances just by declaring but not initializing.

       

      For example:
       

      var test : Dictionary<String, String>
       test.updateValue("1", forKey: "1")   
      test["1"] = "1" // same error as below  

       
      In this case, the compiler does emit the below error:
      variable 'test' passed by reference before being initialized
       
      I think we can redact "passed by reference" cos Swift guide https://docs.swift.org/swift-book/LanguageGuide/Methods.html doesn't explicitly state that internally we pass object by reference and this SO thread https://stackoverflow.com/questions/24838015/variable-p-passed-by-reference-before-being-initialized gives us an interesting example where the user keeps asking why the phrase "passed by reference" is used.
       
       

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            srinikhil07 Nikhil
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated: