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

ExpressibleByStringInterpolation: can't distinguish between literal components and String arguments

    XMLWordPrintable

    Details

      Description

      The interface for ExpressibleByStringInterpolation provides no distinction between components of the literal format string and interpolation components whose type is String.

      struct Example: ExpressibleByStringInterpolation
      {
          init(stringInterpolation strings: Example...) { ... }
          
          init<T>(stringInterpolationSegment expr: T) {
              // General case, specialized below
          }
          init(stringInterpolationSegment expr: Int) {
              // This component is an Int
          }
          init(stringInterpolationSegment expr: String) {
              // This component is EITHER a literal OR a String-typed interpolation segment?
              // This initializer will be called 3 times for the example below.
          }
      }
      
      let x = "def"
      let thing: Example = "abc\(x)ghi"
      

      Expected Results:
      There should be some way (an appropriate specialization, or another initializer in the protocol) to distinguish components of the interpolation literal from string values, to allow completely custom string-interpolation processing.

      Actual Results:
      The same specialization is used for the surrounding string literal and String-typed interpolation segments.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                brentdax Brent Royal-Gordon
                Reporter:
                jtbandes Jacob Bandes-Storch
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated: