Skip to content

Commit 1a81898

Browse files
committed
[Runtime] Include tuple labels when printing the runtime name of a type.
When we started recording labels within the metadata for a tuple type, we failed to print those labels when rendering the type name from metadata.
1 parent 04b7201 commit 1a81898

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

stdlib/public/runtime/Casting.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,26 @@ static void _buildNameForMetadata(const Metadata *type,
285285
auto tuple = static_cast<const TupleTypeMetadata *>(type);
286286
result += "(";
287287
auto elts = tuple->getElements();
288+
const char *labels = tuple->Labels;
288289
for (unsigned i = 0, e = tuple->NumElements; i < e; ++i) {
289290
if (i > 0)
290291
result += ", ";
292+
293+
// If we have any labels, add the label.
294+
if (labels) {
295+
// Labels are space-separated.
296+
if (const char *space = strchr(labels, ' ')) {
297+
if (labels != space) {
298+
result.append(labels, space - labels);
299+
result += ": ";
300+
}
301+
302+
labels = space + 1;
303+
} else {
304+
labels = nullptr;
305+
}
306+
}
307+
291308
_buildNameForMetadata(elts[i].Type, TypeSyntaxLevel::Type, qualified,
292309
result);
293310
}

test/Interpreter/typeof.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ class Meltdown : Error {
5151

5252
class GrilledCheese : Meltdown {}
5353

54+
func labeledTuple() -> (x: Int, y: Int, Double) {
55+
return (x: 1, y: 1, 3.14159)
56+
}
57+
5458
// CHECK: Beads?
5559
classMetatype(type(of: B()))
5660
// CHECK: Deeds?
@@ -81,3 +85,5 @@ print(boxedExistentialMetatype(Meltdown()))
8185
print(boxedExistentialMetatype(GrilledCheese()))
8286
// CHECK: GrilledCheese
8387
print(boxedExistentialMetatype(GrilledCheese() as Meltdown))
88+
// CHECK: (x: Int, y: Int, Double)
89+
print(type(of: labeledTuple()))

0 commit comments

Comments
 (0)