Skip to content

Commit 2b99d2b

Browse files
Merge pull request swiftlang#32945 from AnthonyLatsis/silly-bug
AssociatedTypeInference: Stop skipping the current protocol when looking for a fixed type witness
2 parents 008cc3c + b37491a commit 2b99d2b

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

Diff for: lib/Sema/TypeCheckProtocolInference.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,8 @@ Type AssociatedTypeInference::computeFixedTypeWitness(
807807
// require a fixed type for this associated type.
808808
Type resultType;
809809
for (auto conformedProto : adoptee->getAnyNominal()->getAllProtocols()) {
810-
if (!conformedProto->inheritsFrom(assocType->getProtocol()))
810+
if (conformedProto != assocType->getProtocol() &&
811+
!conformedProto->inheritsFrom(assocType->getProtocol()))
811812
continue;
812813

813814
const auto genericSig = conformedProto->getGenericSignature();

Diff for: test/IDE/complete_opaque_result.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ class TestClass :
143143
// OVERRIDE-DAG: Decl[InstanceMethod]/Super: func returnAssocWithConstraintAndDefault() -> ConcreteMyProtocol {|};
144144
// OVERRIDE-DAG: Decl[InstanceMethod]/Super: func returnAssocWithAnyObjectConstraint() -> some MyProtocol & AnyObject {|}
145145
// OVERRIDE-DAG: Decl[InstanceMethod]/Super: func returnAssocWithConstraintOnProto() -> some MyProtocol {|}
146-
// OVERRIDE-DAG: Decl[InstanceMethod]/Super: func returnAssocWithSameTypeConstraint() -> AssocWithSameTypeConstraint {|}
146+
// OVERRIDE-DAG: Decl[InstanceMethod]/Super: func returnAssocWithSameTypeConstraint() -> ConcreteMyProtocol {|}
147147
// OVERRIDE-DAG: Decl[InstanceMethod]/Super: func returnAssocWithConformanceConstraintGeneric<T>(arg: T) -> AssocWithConformanceConstraintGeneric {|}
148148
// OVERRIDE: End completions
149149
}

Diff for: test/decl/protocol/req/associated_type_inference_fixed_type.swift

+7-11
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
// RUN: %target-typecheck-verify-swift
22

33
protocol P1 where A == Never {
4-
associatedtype A // expected-note {{protocol requires nested type 'A'}}
4+
associatedtype A
55
}
6-
// FIXME: Should this infer A := Never?
7-
struct S1: P1 {} // expected-error {{type 'S1' does not conform to protocol 'P1'}}
6+
struct S1: P1 {} // OK, A := Never
87

98
protocol P2a {
109
associatedtype A
@@ -54,22 +53,19 @@ protocol P7b: P7a where A == Bool {}
5453
struct S7: P7b {}
5554

5655
protocol P8 where A == Bool {
57-
associatedtype A // expected-note {{protocol requires nested type 'A'}}
56+
associatedtype A
5857
}
59-
// expected-error@+2 {{type 'S8' does not conform to protocol 'P7a'}}
60-
// expected-error@+1 {{type 'S8' does not conform to protocol 'P8'}}
58+
// expected-error@+2 {{'P7a' requires the types 'S8.A' (aka 'Bool') and 'Never' be equivalent}}
59+
// expected-note@+1 {{requirement specified as 'Self.A' == 'Never' [with Self = S8]}}
6160
struct S8: P8, P7a {}
6261

6362
protocol P9a where A == Never {
6463
associatedtype A
6564
}
6665
protocol P9b: P9a {
67-
associatedtype A // expected-note {{protocol requires nested type 'A'}}
66+
associatedtype A
6867
}
69-
// FIXME: Associated type restatement sabotages the conformance.
70-
// expected-error@+2 {{type 'S9a' does not conform to protocol 'P9a'}}
71-
// expected-error@+1 {{type 'S9a' does not conform to protocol 'P9b'}}
72-
struct S9a: P9b {}
68+
struct S9a: P9b {} // OK, A := Never
7369
// expected-error@+2 {{'P9a' requires the types 'S9b.A' (aka 'Bool') and 'Never' be equivalent}}
7470
// expected-note@+1 {{requirement specified as 'Self.A' == 'Never' [with Self = S9b]}}
7571
struct S9b: P9b {

0 commit comments

Comments
 (0)