Skip to content

Commit a7f259a

Browse files
committed
---
yaml --- r: 345579 b: refs/heads/master c: e5932fb h: refs/heads/master i: 345577: 7202dfb 345575: a8f2cdd
1 parent 4024b27 commit a7f259a

14 files changed

+62
-31
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: bc81844530df3ce418dab0da73653171f1bbd5be
2+
refs/heads/master: e5932fb2d3eedc05a3d566cac6e891b5e80064d1
33
refs/heads/master-next: 203b3026584ecad859eb328b2e12490099409cd5
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea

trunk/lib/Sema/CSDiagnostics.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,14 @@ Type RequirementFailure::getOwnerType() const {
8282
return getType(getAnchor())->getInOutObjectType()->getMetatypeInstanceType();
8383
}
8484

85+
const GenericContext *RequirementFailure::getGenericContext() const {
86+
if (auto *genericCtx = AffectedDecl->getAsGenericContext())
87+
return genericCtx;
88+
return AffectedDecl->getDeclContext()->getAsDecl()->getAsGenericContext();
89+
}
90+
8591
const Requirement &RequirementFailure::getRequirement() const {
86-
auto *genericCtx = AffectedDecl->getAsGenericContext();
87-
return genericCtx->getGenericRequirements()[getRequirementIndex()];
92+
return getGenericContext()->getGenericRequirements()[getRequirementIndex()];
8893
}
8994

9095
ValueDecl *RequirementFailure::getDeclRef() const {
@@ -139,7 +144,7 @@ bool RequirementFailure::diagnoseAsError() {
139144

140145
auto *anchor = getAnchor();
141146
const auto *reqDC = getRequirementDC();
142-
auto *genericCtx = AffectedDecl->getAsGenericContext();
147+
auto *genericCtx = getGenericContext();
143148

144149
if (reqDC != genericCtx) {
145150
auto *NTD = reqDC->getSelfNominalTypeDecl();

trunk/lib/Sema/CSDiagnostics.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ class RequirementFailure : public FailureDiagnostic {
186186
/// The generic base type where failing requirement comes from.
187187
Type getOwnerType() const;
188188

189+
/// Generic context associated with the failure.
190+
const GenericContext *getGenericContext() const;
191+
189192
/// Generic requirement associated with the failure.
190193
const Requirement &getRequirement() const;
191194

trunk/lib/Sema/ConstraintSystem.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2045,6 +2045,15 @@ bool ConstraintSystem::salvage(SmallVectorImpl<Solution> &viable, Expr *expr) {
20452045
SolverState state(expr, *this, FreeTypeVariableBinding::Disallow);
20462046
state.recordFixes = true;
20472047

2048+
// Retry all inactive and failed constraints
2049+
if (failedConstraint) {
2050+
addUnsolvedConstraint(failedConstraint);
2051+
failedConstraint = nullptr;
2052+
}
2053+
ActiveConstraints.splice(ActiveConstraints.end(), InactiveConstraints);
2054+
for (auto &constraint : ActiveConstraints)
2055+
constraint.setActive(true);
2056+
20482057
// Solve the system.
20492058
solve(viable);
20502059

trunk/test/Constraints/generics.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ do {
563563
}
564564

565565
func rdar35890334(_ arr: inout [Int]) {
566-
_ = arr.popFirst() // expected-error {{value of type '[Int]' has no member 'popFirst'}}
566+
_ = arr.popFirst() // expected-error {{referencing instance method 'popFirst()' on 'Collection' requires the types '[Int]' and 'ArraySlice<Int>' be equivalent}}
567567
}
568568

569569
// rdar://problem/39616039
@@ -621,3 +621,11 @@ func rdar40537858() {
621621
let _: E = .foo(s) // expected-error {{generic enum 'E' requires that 'S' conform to 'P'}}
622622
let _: E = .bar([s]) // expected-error {{generic enum 'E' requires that 'S' conform to 'P'}}
623623
}
624+
625+
// SR-8934
626+
struct BottleLayout {
627+
let count : Int
628+
}
629+
let arr = [BottleLayout]()
630+
let layout = BottleLayout(count:1)
631+
let ix = arr.firstIndex(of:layout) // expected-error {{argument type 'BottleLayout' does not conform to expected type 'Equatable'}}

trunk/test/decl/ext/generic.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ extension GenericOverloads where T : P1, U : P2 {
9797
subscript (i: Int) -> Int { return i }
9898
}
9999

100-
extension Array where Element : Hashable {
100+
extension Array where Element : Hashable { // expected-note {{where 'Element' = 'T'}}
101101
var worseHashEver: Int {
102102
var result = 0
103103
for elt in self {
@@ -108,7 +108,7 @@ extension Array where Element : Hashable {
108108
}
109109

110110
func notHashableArray<T>(_ x: [T]) {
111-
x.worseHashEver // expected-error{{type 'T' does not conform to protocol 'Hashable'}}
111+
x.worseHashEver // expected-error{{property 'worseHashEver' requires that 'T' conform to 'Hashable'}}
112112
}
113113

114114
func hashableArray<T : Hashable>(_ x: [T]) {
@@ -132,7 +132,7 @@ func genericClassEquatable<T : Equatable>(_ gc: GenericClass<T>, x: T, y: T) {
132132
}
133133

134134
func genericClassNotEquatable<T>(_ gc: GenericClass<T>, x: T, y: T) {
135-
gc.foo(x, y: y) // expected-error{{type 'T' does not conform to protocol 'Equatable'}}
135+
gc.foo(x, y: y) // expected-error{{argument type 'T' does not conform to expected type 'Equatable'}}
136136
}
137137

138138

trunk/test/decl/ext/protocol.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ struct S4d : P4 {
208208
func reqP4a() -> Bool { return false }
209209
}
210210

211-
extension P4 where Self.AssocP4 == Int {
212-
func extP4Int() { } // expected-note {{candidate requires that the types 'Bool' and 'Int' be equivalent (requirement specified as 'Self.AssocP4' == 'Int')}}
211+
extension P4 where Self.AssocP4 == Int { // expected-note {{where 'Self.AssocP4' = 'Bool'}}
212+
func extP4Int() { }
213213
}
214214

215215
extension P4 where Self.AssocP4 == Bool {
@@ -229,7 +229,7 @@ func testP4(_ s4a: S4a, s4b: S4b, s4c: S4c, s4d: S4d) {
229229
s4c.extP4Int() // okay
230230
var b1 = s4d.extP4a() // okay, "Bool" version
231231
b1 = true // checks type above
232-
s4d.extP4Int() // expected-error{{value of type 'S4d' has no member 'extP4Int'}}
232+
s4d.extP4Int() // expected-error{{referencing instance method 'extP4Int()' on 'P4' requires the types 'Bool' and 'Int' be equivalent}}
233233
_ = b1
234234
}
235235

trunk/test/decl/nested/type_in_type.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ protocol ExpressibleByDogLiteral {}
377377
struct Kitten : ExpressibleByCatLiteral {}
378378
struct Puppy : ExpressibleByDogLiteral {}
379379

380-
struct Claws<A: ExpressibleByCatLiteral> {
380+
struct Claws<A: ExpressibleByCatLiteral> { // expected-note {{'A' declared as parameter to type 'Claws'}}
381381
struct Fangs<B: ExpressibleByDogLiteral> { }
382382
}
383383

@@ -402,7 +402,8 @@ func test() {
402402
let _: Claws.Fangs<NotADog> = something()
403403
// expected-error@-1 {{generic parameter 'T' could not be inferred}} // FIXME: bad diagnostic
404404
_ = Claws.Fangs<NotADog>()
405-
// expected-error@-1 {{type 'NotADog' does not conform to protocol 'ExpressibleByDogLiteral'}}
405+
// expected-error@-1 {{generic parameter 'A' could not be inferred}}
406+
// expected-note@-2 {{explicitly specify the generic arguments to fix this issue}}
406407
}
407408

408409
// https://bugs.swift.org/browse/SR-4379

trunk/test/decl/protocol/special/coding/class_codable_simple_conditional.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Conditional<T> {
2121
}
2222
}
2323

24-
extension Conditional: Codable where T: Codable {
24+
extension Conditional: Codable where T: Codable { // expected-note 2 {{where 'T' = 'Nonconforming'}}
2525
// expected-error@-1 2 {{implementation of 'Decodable' for non-final class cannot be automatically synthesized in extension because initializer requirement 'init(from:)' can only be be satisfied by a 'required' initializer in the class definition}}
2626
}
2727

@@ -32,7 +32,8 @@ let _ = Conditional<Int>.encode(to:)
3232
// but only for Codable parameters.
3333
struct Nonconforming {}
3434
let _ = Conditional<Nonconforming>.init(from:) // expected-error {{type 'Conditional<Nonconforming>' has no member 'init(from:)'}}
35-
let _ = Conditional<Nonconforming>.encode(to:) // expected-error {{type 'Nonconforming' does not conform to protocol 'Decodable'}}
35+
let _ = Conditional<Nonconforming>.encode(to:) // expected-error {{referencing instance method 'encode(to:)' on 'Conditional' requires that 'Nonconforming' conform to 'Decodable'}}
36+
// expected-error@-1 {{referencing instance method 'encode(to:)' on 'Conditional' requires that 'Nonconforming' conform to 'Encodable'}}
3637

3738
// The synthesized CodingKeys type should not be accessible from outside the
3839
// struct.

trunk/test/decl/protocol/special/coding/class_codable_simple_conditional_final.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,18 @@ final class Conditional<T> {
2020
}
2121
}
2222

23-
extension Conditional: Codable where T: Codable {}
23+
extension Conditional: Codable where T: Codable {} // expected-note 4 {{where 'T' = 'Nonconforming'}}
2424

2525
// They should receive synthesized init(from:) and an encode(to:).
2626
let _ = Conditional<Int>.init(from:)
2727
let _ = Conditional<Int>.encode(to:)
2828

2929
// but only for Codable parameters.
3030
struct Nonconforming {}
31-
let _ = Conditional<Nonconforming>.init(from:) // expected-error {{type 'Nonconforming' does not conform to protocol 'Decodable'}}
32-
let _ = Conditional<Nonconforming>.encode(to:) // expected-error {{type 'Nonconforming' does not conform to protocol 'Decodable'}}
31+
let _ = Conditional<Nonconforming>.init(from:) // expected-error {{referencing initializer 'init(from:)' on 'Conditional' requires that 'Nonconforming' conform to 'Encodable'}}
32+
//expected-error@-1 {{referencing initializer 'init(from:)' on 'Conditional' requires that 'Nonconforming' conform to 'Decodable'}}
33+
let _ = Conditional<Nonconforming>.encode(to:) // expected-error {{referencing instance method 'encode(to:)' on 'Conditional' requires that 'Nonconforming' conform to 'Decodable'}}
34+
//expected-error@-1 {{referencing instance method 'encode(to:)' on 'Conditional' requires that 'Nonconforming' conform to 'Encodable'}}
3335

3436
// The synthesized CodingKeys type should not be accessible from outside the
3537
// struct.

trunk/test/decl/protocol/special/coding/class_codable_simple_conditional_final_separate.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ final class Conditional<T> {
2020
}
2121
}
2222

23-
extension Conditional: Encodable where T: Encodable {
23+
extension Conditional: Encodable where T: Encodable { // expected-note {{where 'T' = 'OnlyDec'}}
2424
}
2525

26-
extension Conditional: Decodable where T: Decodable {
26+
extension Conditional: Decodable where T: Decodable { // expected-note {{where 'T' = 'OnlyEnc'}}
2727
}
2828

2929
struct OnlyEnc: Encodable {}
@@ -34,8 +34,8 @@ let _ = Conditional<OnlyDec>.init(from:)
3434
let _ = Conditional<OnlyEnc>.encode(to:)
3535

3636
// but only for the appropriately *codable parameters.
37-
let _ = Conditional<OnlyEnc>.init(from:) // expected-error {{type 'OnlyEnc' does not conform to protocol 'Decodable'}}
38-
let _ = Conditional<OnlyDec>.encode(to:) // expected-error {{type 'OnlyDec' does not conform to protocol 'Encodable'}}
37+
let _ = Conditional<OnlyEnc>.init(from:) // expected-error {{referencing initializer 'init(from:)' on 'Conditional' requires that 'OnlyEnc' conform to 'Decodable'}}
38+
let _ = Conditional<OnlyDec>.encode(to:) // expected-error {{referencing instance method 'encode(to:)' on 'Conditional' requires that 'OnlyDec' conform to 'Encodable'}}
3939

4040
// The synthesized CodingKeys type should not be accessible from outside the
4141
// struct.

trunk/test/decl/protocol/special/coding/class_codable_simple_conditional_separate.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Conditional<T> {
2121
}
2222
}
2323

24-
extension Conditional: Encodable where T: Encodable {
24+
extension Conditional: Encodable where T: Encodable { // expected-note {{where 'T' = 'OnlyDec'}}
2525
}
2626

2727
extension Conditional: Decodable where T: Decodable {
@@ -37,7 +37,7 @@ let _ = Conditional<OnlyEnc>.encode(to:)
3737

3838
// but only for the appropriately *codable parameters.
3939
let _ = Conditional<OnlyEnc>.init(from:) // expected-error {{type 'Conditional<OnlyEnc>' has no member 'init(from:)'}}
40-
let _ = Conditional<OnlyDec>.encode(to:) // expected-error {{type 'OnlyDec' does not conform to protocol 'Encodable'}}
40+
let _ = Conditional<OnlyDec>.encode(to:) // expected-error {{referencing instance method 'encode(to:)' on 'Conditional' requires that 'OnlyDec' conform to 'Encodable'}}
4141

4242
// The synthesized CodingKeys type should not be accessible from outside the
4343
// struct.

trunk/test/decl/protocol/special/coding/struct_codable_simple_conditional.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ struct Conditional<T> {
1616
}
1717
}
1818

19-
extension Conditional: Codable where T: Codable {
19+
extension Conditional: Codable where T: Codable { // expected-note 4{{where 'T' = 'Nonconforming'}}
2020
}
2121

2222
// They should receive synthesized init(from:) and an encode(to:).
@@ -25,8 +25,10 @@ let _ = Conditional<Int>.encode(to:)
2525

2626
// but only for Codable parameters.
2727
struct Nonconforming {}
28-
let _ = Conditional<Nonconforming>.init(from:) // expected-error {{type 'Nonconforming' does not conform to protocol 'Decodable'}}
29-
let _ = Conditional<Nonconforming>.encode(to:) // expected-error {{type 'Nonconforming' does not conform to protocol 'Decodable'}}
28+
let _ = Conditional<Nonconforming>.init(from:) // expected-error {{referencing initializer 'init(from:)' on 'Conditional' requires that 'Nonconforming' conform to 'Encodable'}}
29+
// expected-error@-1 {{referencing initializer 'init(from:)' on 'Conditional' requires that 'Nonconforming' conform to 'Decodable'}}
30+
let _ = Conditional<Nonconforming>.encode(to:) // expected-error {{referencing instance method 'encode(to:)' on 'Conditional' requires that 'Nonconforming' conform to 'Encodable'}}
31+
// expected-error@-1 {{referencing instance method 'encode(to:)' on 'Conditional' requires that 'Nonconforming' conform to 'Decodable'}}
3032

3133
// The synthesized CodingKeys type should not be accessible from outside the
3234
// struct.

trunk/test/decl/protocol/special/coding/struct_codable_simple_conditional_separate.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ struct Conditional<T> {
1616
}
1717
}
1818

19-
extension Conditional: Encodable where T: Encodable {
19+
extension Conditional: Encodable where T: Encodable { // expected-note {{where 'T' = 'OnlyDec'}}
2020
}
21-
extension Conditional: Decodable where T: Decodable {
21+
extension Conditional: Decodable where T: Decodable { // expected-note {{where 'T' = 'OnlyEnc'}}
2222
}
2323

2424
struct OnlyEnc: Encodable {}
@@ -29,8 +29,8 @@ let _ = Conditional<OnlyDec>.init(from:)
2929
let _ = Conditional<OnlyEnc>.encode(to:)
3030

3131
// but only for the appropriately *codable parameters.
32-
let _ = Conditional<OnlyEnc>.init(from:) // expected-error {{type 'OnlyEnc' does not conform to protocol 'Decodable'}}
33-
let _ = Conditional<OnlyDec>.encode(to:) // expected-error {{type 'OnlyDec' does not conform to protocol 'Encodable'}}
32+
let _ = Conditional<OnlyEnc>.init(from:) // expected-error {{referencing initializer 'init(from:)' on 'Conditional' requires that 'OnlyEnc' conform to 'Decodable'}}
33+
let _ = Conditional<OnlyDec>.encode(to:) // expected-error {{referencing instance method 'encode(to:)' on 'Conditional' requires that 'OnlyDec' conform to 'Encodable'}}
3434

3535
// The synthesized CodingKeys type should not be accessible from outside the
3636
// struct.

0 commit comments

Comments
 (0)