Skip to content

Commit 6216242

Browse files
committed
If the missing generic requirement includes type variables, don't emit an unhelpful note for it.
Fixes SR-12759
1 parent dca0209 commit 6216242

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,9 @@ static Optional<RequirementMatch> findMissingGenericRequirementForSolutionFix(
784784
default:
785785
return Optional<RequirementMatch>();
786786
}
787+
788+
if (missingType->hasTypeVariable())
789+
return Optional<RequirementMatch>();
787790

788791
auto missingRequirementMatch = [&](Type type) -> RequirementMatch {
789792
Requirement requirement(requirementKind, type, missingType);

test/decl/protocol/req/missing_conformance.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,31 @@ struct S3 : P12 { // expected-error {{type 'S3' does not conform to protocol 'P1
110110
// expected-note@-1 {{candidate can not infer 'A' = 'P11' because 'P11' is not a nominal type and so can't conform to 'P11'}}
111111
}
112112

113+
// SR-12759
114+
struct CountSteps1<T> : Collection {
115+
init(count: Int) { self.count = count }
116+
var count: Int
117+
118+
var startIndex: Int { 0 }
119+
var endIndex: Int { count }
120+
func index(after i: Int) -> Int {
121+
totalSteps += 1 // expected-error {{cannot find 'totalSteps' in scope}}
122+
return i + 1
123+
}
124+
subscript(i: Int) -> Int { return i }
125+
}
126+
127+
extension CountSteps1 // expected-error {{type 'CountSteps1<T>' does not conform to protocol 'RandomAccessCollection'}}
128+
// expected-error@-1 {{conditional conformance of type 'CountSteps1<T>' to protocol 'RandomAccessCollection' does not imply conformance to inherited protocol 'BidirectionalCollection'}}
129+
// expected-note@-2 {{did you mean to explicitly state the conformance like 'extension CountSteps1: BidirectionalCollection where ...'?}}
130+
// expected-error@-3 {{type 'CountSteps1<T>' does not conform to protocol 'BidirectionalCollection'}}
131+
: RandomAccessCollection
132+
where T : Equatable
133+
{
134+
typealias Index = Int
135+
func index(_ i: Index, offsetBy d: Int) -> Index {
136+
return i + d
137+
}
138+
}
139+
140+

0 commit comments

Comments
 (0)