Skip to content

[Runtime] Adjust to conforming type when instantiating witness table. #24759

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
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: 2 additions & 1 deletion stdlib/public/runtime/ProtocolConformance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,8 @@ swift_conformsToProtocolImpl(const Metadata * const type,
if (!description)
return nullptr;

return description->getWitnessTable(type);
return description->getWitnessTable(
findConformingSuperclass(type, description));
}

const ContextDescriptor *
Expand Down
47 changes: 47 additions & 0 deletions test/Runtime/associated_type_demangle_inherited.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// RUN: %empty-directory(%t)
// RUN: %target-build-swift -parse-stdlib %s -module-name main -o %t/a.out
// RUN: %target-codesign %t/a.out
// RUN: %target-run %t/a.out
// REQUIRES: executable_test

import Swift
import StdlibUnittest

class Key<T>: RawRepresentable {
typealias RawValue = T

let rawValue: T

required init(rawValue: T) {
self.rawValue = rawValue
}
}

extension Key: Hashable where T: Hashable {
func hash(into hasher: inout Hasher) {
hasher.combine(rawValue)
}
}

extension Key: Equatable where T: Equatable {
static func == (lhs: Key, rhs: Key) -> Bool {
return lhs.rawValue == rhs.rawValue
}
}

class SpecificKey: Key<String> { }

extension SpecificKey {
static let name = SpecificKey(rawValue: "name")
}

let AssociatedTypeDemangleTests = TestSuite("AssociatedTypeDemangle")

AssociatedTypeDemangleTests.test("superclass substitutions") {
var dictionary: [SpecificKey: String] = [:]
dictionary[SpecificKey.name] = "Hello"

expectEqual(["Hello"], dictionary.values.map { $0 })
}

runAllTests()