Skip to content

Commit 2935301

Browse files
authored
Merge pull request #7124 from DougGregor/string-interpolation-generic
Replace concrete init(stringInterpolationSegment:)'s with generic ones
2 parents 74dcb48 + f6cac54 commit 2935301

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

stdlib/public/core/StringInterpolation.swift.gyb

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,29 +68,35 @@ extension String : _ExpressibleByStringInterpolation {
6868
self = String(describing: expr)
6969
}
7070

71-
% for Type in StreamableTypes:
7271
/// Creates a string containing the given value's textual representation.
7372
///
7473
/// Do not call this initializer directly. It is used by the compiler when
7574
/// interpreting string interpolations.
7675
///
7776
/// - SeeAlso: `ExpressibleByStringInterpolation`
78-
public init(stringInterpolationSegment expr: ${Type}) {
77+
public init<T: TextOutputStreamable> (stringInterpolationSegment expr: T) {
7978
self = _toStringReadOnlyStreamable(expr)
8079
}
81-
% end
8280

83-
% for Type in PrintableTypes:
8481
/// Creates a string containing the given value's textual representation.
8582
///
8683
/// Do not call this initializer directly. It is used by the compiler when
8784
/// interpreting string interpolations.
8885
///
8986
/// - SeeAlso: `ExpressibleByStringInterpolation`
90-
public init(stringInterpolationSegment expr: ${Type}) {
87+
public init<T: CustomStringConvertible> (stringInterpolationSegment expr: T) {
9188
self = _toStringReadOnlyPrintable(expr)
9289
}
93-
% end
90+
91+
/// Creates a string containing the given value's textual representation.
92+
///
93+
/// Do not call this initializer directly. It is used by the compiler when
94+
/// interpreting string interpolations.
95+
///
96+
/// - SeeAlso: `ExpressibleByStringInterpolation`
97+
public init<T: TextOutputStreamable & CustomStringConvertible> (stringInterpolationSegment expr: T) {
98+
self = _toStringReadOnlyStreamable(expr)
99+
}
94100
}
95101

96102
// ${'Local Variables'}:

test/api-digester/source-stability.swift.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Protocol IndexableBase has been removed (deprecated)
1212
Protocol MutableIndexable has been removed (deprecated)
1313
Protocol RandomAccessIndexable has been removed (deprecated)
1414
Protocol RangeReplaceableIndexable has been removed (deprecated)
15+
Constructor String.init(stringInterpolationSegment:) has been removed
1516
Func Array.append(contentsOf:) has been removed
1617
Func ArraySlice.append(contentsOf:) has been removed
1718
Func ContiguousArray.append(contentsOf:) has been removed
@@ -34,6 +35,7 @@ Constructor RangeReplaceableBidirectionalSlice.init(base:bounds:) has 2nd parame
3435
Constructor RangeReplaceableRandomAccessSlice.init(base:bounds:) has 2nd parameter type change from Range<Base.Index> to Range<RangeReplaceableRandomAccessSlice.Index>
3536
Constructor RangeReplaceableSlice.init(base:bounds:) has 2nd parameter type change from Range<Base.Index> to Range<RangeReplaceableSlice.Index>
3637
Constructor Slice.init(base:bounds:) has 2nd parameter type change from Range<Base.Index> to Range<Slice.Index>
38+
Constructor String.init(stringInterpolationSegment:) has 1st parameter type change from String to T
3739
Func AnyBidirectionalCollection.makeIterator() has return type change from AnyIterator<Element> to AnyBidirectionalCollection.Iterator
3840
Func AnyCollection.makeIterator() has return type change from AnyIterator<Element> to AnyCollection.Iterator
3941
Func AnyRandomAccessCollection.makeIterator() has return type change from AnyIterator<Element> to AnyRandomAccessCollection.Iterator
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// RUN: not %target-swift-frontend -typecheck %s
2+
3+
let query = "<#...#>=\(<#...#>)&<#...#>=\(<#...#>)&<#...#>=\(<#...#>)&<#...#>=\(<#...#>)&<#...#>=\(<#...#>)&<#...#>=\(<#...#>)&<#...#>=\(<#...#>)&<#...#>=\(<#...#>)&<#...#>=\(<#...#>)&<#...#>=\(<#...#>)&<#...#>=\(<#...#>)&<#...#>=\(<#...#>)&<#...#>=\(<#...#>)&<#...#>=\(<#...#>)&<#...#>=\(<#...#>)&<#...#>=\(<#...#>)"
4+

0 commit comments

Comments
 (0)