Skip to content

Commit f0447c1

Browse files
authored
Merge pull request #19754 from DougGregor/objc-assoc-type-crash
2 parents 0178cb1 + 9565f0d commit f0447c1

File tree

4 files changed

+87
-7
lines changed

4 files changed

+87
-7
lines changed

lib/AST/Decl.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3651,13 +3651,22 @@ ProtocolDecl::getInheritedProtocols() const {
36513651
llvm::TinyPtrVector<AssociatedTypeDecl *>
36523652
ProtocolDecl::getAssociatedTypeMembers() const {
36533653
llvm::TinyPtrVector<AssociatedTypeDecl *> result;
3654-
if (!isObjC()) {
3655-
for (auto member : getMembers()) {
3656-
if (auto ATD = dyn_cast<AssociatedTypeDecl>(member)) {
3657-
result.push_back(ATD);
3658-
}
3654+
3655+
// Clang-imported protocols never have associated types.
3656+
if (hasClangNode())
3657+
return result;
3658+
3659+
// Deserialized @objc protocols never have associated types.
3660+
if (!getParentSourceFile() && isObjC())
3661+
return result;
3662+
3663+
// Find the associated type declarations.
3664+
for (auto member : getMembers()) {
3665+
if (auto ATD = dyn_cast<AssociatedTypeDecl>(member)) {
3666+
result.push_back(ATD);
36593667
}
36603668
}
3669+
36613670
return result;
36623671
}
36633672

validation-test/Runtime/sr8666.swift

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// RUN: %target-run-simple-swift
2+
// REQUIRES: executable_test
3+
4+
private protocol AnyChangeTracker {
5+
var myVariable: Any? { get }
6+
var isModified: Bool { get }
7+
}
8+
9+
protocol ChangeTrackerType {
10+
associatedtype Value
11+
var originalValue: Value { get }
12+
var value: Value { get set }
13+
var isModified: Bool { get }
14+
}
15+
16+
extension ChangeTrackerType where Value: Equatable {
17+
var isModified: Bool {
18+
return value != originalValue
19+
}
20+
}
21+
22+
struct ChangeTracker<T: Equatable>: ChangeTrackerType {
23+
let originalValue: T
24+
var value: T
25+
26+
init(value: T) {
27+
originalValue = value
28+
self.value = value
29+
}
30+
}
31+
32+
extension ChangeTracker: AnyChangeTracker where Value: OptionalType, Value.Wrapped: Equatable {
33+
var myVariable: Any? {
34+
return value
35+
}
36+
}
37+
38+
protocol OptionalType {
39+
associatedtype Wrapped
40+
var value: Wrapped? { get }
41+
}
42+
43+
extension Optional: OptionalType {
44+
var value: Wrapped? {
45+
return self
46+
}
47+
}
48+
49+
let s: Any = ChangeTracker<String?>(value: "Foo")
50+
51+
guard let s = s as? AnyChangeTracker else {
52+
fatalError("Does not comply to AnyChangeTracker")
53+
}
54+
55+
let myVar = String(describing: s.myVariable ?? "nil")
56+
assert(myVar == "Optional(\"Foo\")")
57+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: not %target-swift-frontend -typecheck %s
2+
3+
@objc protocol Foo {
4+
associatedtype Bar
5+
var property: Generic<Bar> { get }
6+
}
7+
8+
class Generic<Element> {
9+
}
10+
11+
class FooImpl<T>: NSObject, Foo {
12+
let property: Generic<T>
13+
}
14+

validation-test/compiler_crashers/28859-resolver-unable-to-resolve-type-witness.swift renamed to validation-test/compiler_crashers_fixed/28859-resolver-unable-to-resolve-type-witness.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
// See https://swift.org/LICENSE.txt for license information
66
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
77

8-
// REQUIRES: asserts
9-
// RUN: not --crash %target-swift-frontend %s -emit-ir
8+
9+
// RUN: not %target-swift-frontend %s -emit-ir
1010
class a:P@objc protocol P{{}func a:a{}{}typealias a

0 commit comments

Comments
 (0)