Skip to content

Commit 1f731be

Browse files
authored
Merge pull request #5865 from DougGregor/unsatisfiable-req-swift-3
2 parents ae648c1 + f8c45dd commit 1f731be

File tree

5 files changed

+36
-3
lines changed

5 files changed

+36
-3
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,6 +1291,10 @@ ERROR(requirement_restricts_self,none,
12911291
"%0 requirement %1 cannot add constraint '%2%select{:|:| ==|:}3 %4' on "
12921292
"'Self'",
12931293
(DescriptiveDeclKind, DeclName, StringRef, unsigned, StringRef))
1294+
WARNING(requirement_restricts_self_swift3,none,
1295+
"adding constraint '%2%select{:|:| ==|:}3 %4' on 'Self' via %0 "
1296+
"requirement %1 is deprecated in Swift 3",
1297+
(DescriptiveDeclKind, DeclName, StringRef, unsigned, StringRef))
12941298
ERROR(witness_argument_name_mismatch,none,
12951299
"%select{method|initializer}0 %1 has different argument names from those "
12961300
"required by protocol %2 (%3)", (bool, DeclName, Type, DeclName))

lib/Sema/TypeCheckGeneric.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,13 +529,17 @@ TypeChecker::validateGenericFuncSignature(AbstractFunctionDecl *func) {
529529
req.getFirstType()->is<GenericTypeParamType>())
530530
continue;
531531

532-
diagnose(func, diag::requirement_restricts_self,
532+
diagnose(func,
533+
Context.LangOpts.EffectiveLanguageVersion[0] >= 4
534+
? diag::requirement_restricts_self
535+
: diag::requirement_restricts_self_swift3,
533536
func->getDescriptiveKind(), func->getFullName(),
534537
req.getFirstType().getString(),
535538
static_cast<unsigned>(req.getKind()),
536539
req.getSecondType().getString());
537540

538-
invalid = true;
541+
if (Context.LangOpts.EffectiveLanguageVersion[0] >= 4)
542+
invalid = true;
539543
}
540544
}
541545

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: %target-parse-verify-swift -swift-version 3
2+
3+
protocol P {
4+
associatedtype A
5+
associatedtype B
6+
7+
func f<T: P>(_: T) where T.A == Self.A, T.A == Self.B // expected-warning{{adding constraint 'Self.A == Self.B' on 'Self' via instance method requirement 'f' is deprecated}}
8+
// expected-note@-1{{protocol requires function 'f' with type '<T> (T) -> ()'; do you want to add a stub?}}
9+
}
10+
11+
extension P {
12+
func f<T: P>(_: T) where T.A == Self.A, T.A == Self.B { } // expected-note{{candidate has non-matching type '<Self, T> (T) -> ()'}}
13+
}
14+
15+
struct X : P { // expected-error{{type 'X' does not conform to protocol 'P'}}
16+
typealias A = X
17+
typealias B = Int
18+
}
19+
20+
struct Y : P {
21+
typealias A = Y
22+
typealias B = Y
23+
}
24+

test/decl/protocol/req/unsatisfiable.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-parse-verify-swift
1+
// RUN: %target-parse-verify-swift -swift-version 4
22

33
protocol P {
44
associatedtype A

validation-test/compiler_crashers/28504-anonymous-namespace-verifier-verifychecked-swift-type-llvm-smallptrset-swift-arc.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
77

88
// RUN: not --crash %target-swift-frontend %s -emit-ir
9+
// REQUIRES: non_escaping_type_variables
910
{{}
1011
return.h.h == Int

0 commit comments

Comments
 (0)