Swift StringInterpolationConvertible: can't distinguish between literal components and String arguments

Originator:jtbandes
Number:rdar://19800456 Date Originated:2/11/2015
Status:Duplicate/18681780 Resolved:
Product:OS X SDK Product Version:
Classification: Reproducible:Always
 
Summary:
The interface for StringInterpolationConvertible provides no distinction between components of the literal format string and interpolation components whose type is String.

struct Example: StringInterpolationConvertible
{
    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"

Steps to Reproduce:


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.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!