Skip to content

Commit 82c172c

Browse files
authored
Merge pull request swiftlang#67527 from slavapestov/rdar112866068
Runtime: Lift prohibition on packs in swift_getTypeByMangledName() overload used by mirrors
2 parents a0d5234 + e454458 commit 82c172c

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

stdlib/public/runtime/ReflectionMirror.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,7 @@ getFieldAt(const Metadata *base, unsigned index) {
379379
auto result = swift_getTypeByMangledName(
380380
MetadataState::Complete, typeName, substitutions.getGenericArgs(),
381381
[&substitutions](unsigned depth, unsigned index) {
382-
// FIXME: Variadic generics
383-
return substitutions.getMetadata(depth, index).getMetadata();
382+
return substitutions.getMetadata(depth, index).Ptr;
384383
},
385384
[&substitutions](const Metadata *type, unsigned index) {
386385
return substitutions.getWitnessTable(type, index);

test/stdlib/MirrorWithPacks.swift

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//===--- MirrorWithPacks.swift -----------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2023 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
// RUN: %empty-directory(%t)
13+
// RUN: cp %s %t/main.swift
14+
// RUN: %target-build-swift %t/main.swift -o %t/Mirror -Xfrontend -disable-availability-checking
15+
// RUN: %target-codesign %t/Mirror
16+
// RUN: %target-run %t/Mirror
17+
18+
// REQUIRES: executable_test
19+
// REQUIRES: shell
20+
// REQUIRES: reflection
21+
22+
// rdar://96439408
23+
// UNSUPPORTED: use_os_stdlib
24+
25+
import StdlibUnittest
26+
27+
var mirrors = TestSuite("MirrorWithPacks")
28+
29+
struct Tuple<each T> {
30+
var elements: (repeat each T)
31+
init(_ elements: repeat each T) {
32+
self.elements = (repeat each elements)
33+
}
34+
}
35+
36+
mirrors.test("Packs") {
37+
let value = Tuple("hi", 3, false)
38+
var output = ""
39+
dump(value, to: &output)
40+
41+
let expected =
42+
"▿ Mirror.Tuple<Pack{Swift.String, Swift.Int, Swift.Bool}>\n" +
43+
" ▿ elements: (3 elements)\n" +
44+
" - .0: \"hi\"\n" +
45+
" - .1: 3\n" +
46+
" - .2: false\n"
47+
48+
expectEqual(expected, output)
49+
}
50+
51+
runAllTests()

0 commit comments

Comments
 (0)