Skip to content

Runtime: Lift prohibition on packs in swift_getTypeByMangledName() overload used by mirrors [5.9] #67937

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions stdlib/public/runtime/ReflectionMirror.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,7 @@ getFieldAt(const Metadata *base, unsigned index) {
auto result = swift_getTypeByMangledName(
MetadataState::Complete, typeName, substitutions.getGenericArgs(),
[&substitutions](unsigned depth, unsigned index) {
// FIXME: Variadic generics
return substitutions.getMetadata(depth, index).getMetadata();
return substitutions.getMetadata(depth, index).Ptr;
},
[&substitutions](const Metadata *type, unsigned index) {
return substitutions.getWitnessTable(type, index);
Expand Down
51 changes: 51 additions & 0 deletions test/stdlib/MirrorWithPacks.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//===--- MirrorWithPacks.swift -----------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2023 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
// RUN: %empty-directory(%t)
// RUN: cp %s %t/main.swift
// RUN: %target-build-swift %t/main.swift -o %t/Mirror -Xfrontend -disable-availability-checking
// RUN: %target-codesign %t/Mirror
// RUN: %target-run %t/Mirror

// REQUIRES: executable_test
// REQUIRES: shell
// REQUIRES: reflection

// rdar://96439408
// UNSUPPORTED: use_os_stdlib

import StdlibUnittest

var mirrors = TestSuite("MirrorWithPacks")

struct Tuple<each T> {
var elements: (repeat each T)
init(_ elements: repeat each T) {
self.elements = (repeat each elements)
}
}

mirrors.test("Packs") {
let value = Tuple("hi", 3, false)
var output = ""
dump(value, to: &output)

let expected =
"▿ Mirror.Tuple<Pack{Swift.String, Swift.Int, Swift.Bool}>\n" +
" ▿ elements: (3 elements)\n" +
" - .0: \"hi\"\n" +
" - .1: 3\n" +
" - .2: false\n"

expectEqual(expected, output)
}

runAllTests()