Skip to content

Commit

Permalink
Merge pull request #24759 from DougGregor/runtime-conforming-type-ins…
Browse files Browse the repository at this point in the history
…tantiation

[Runtime] Adjust to conforming type when instantiating witness table.
  • Loading branch information
DougGregor authored May 14, 2019
2 parents 78d0639 + 54d3930 commit 9d573b6
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
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()

0 comments on commit 9d573b6

Please sign in to comment.