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

mechanism to hand through #file/#line in subscripts

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Resolved
    • Priority: Medium
    • Resolution: Done
    • Component/s: Compiler
    • Labels:
      None

      Description

      For my hypothetical MyArray implementation, in normal functions I can write

      function get(index: Int, file: StaticString = #file, line: UInt = #line) -> Value {
          if !checkIndex(index) {
              fatalError("index \(index) out of bound", file: file, line: line)
          }
          ...
      }
      

      and I'll be able to create good error messages for the user.

      In subscripts however, default arguments are disallowed so

      subscript(index: Int) -> Value {
          if !checkIndex(index) {
              fatalError("index \(index) out of bound")
          }
          ....
      }
      

      will always show its literal line and file rather than the callers.

        Attachments

          Activity

            People

            Assignee:
            slavapestov Slava Pestov
            Reporter:
            jw Johannes Weiss
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: