Skip to content

Commit ea7c13e

Browse files
committed
[Diagnostics] For now, don't diagnose layout requirement failures
in MissingConformanceFailure::diagnoseTypeCannotConform.
1 parent 0d95a84 commit ea7c13e

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,8 @@ bool MissingConformanceFailure::diagnoseAsError() {
603603

604604
bool MissingConformanceFailure::diagnoseTypeCannotConform(Expr *anchor,
605605
Type nonConformingType, Type protocolType) const {
606-
if (!(nonConformingType->is<AnyFunctionType>() ||
606+
if (getRequirement().getKind() == RequirementKind::Layout ||
607+
!(nonConformingType->is<AnyFunctionType>() ||
607608
nonConformingType->is<TupleType>() ||
608609
nonConformingType->isExistentialType() ||
609610
nonConformingType->is<AnyMetatypeType>())) {

test/Generics/existential_restrictions.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ func fOP<T : OP>(_ t: T) { }
1616
func fOPE(_ t: OP) { }
1717
func fSP<T : SP>(_ t: T) { }
1818
func fAO<T : AnyObject>(_ t: T) { }
19-
// expected-note@-1 {{required by global function 'fAO' where 'T' = 'P'}}
20-
// expected-note@-2 {{required by global function 'fAO' where 'T' = 'CP'}}
21-
// expected-note@-3 {{required by global function 'fAO' where 'T' = 'OP & P'}}
19+
// expected-note@-1 {{where 'T' = 'P'}}
20+
// expected-note@-2 {{where 'T' = 'CP'}}
21+
// expected-note@-3 {{where 'T' = 'OP & P'}}
2222
func fAOE(_ t: AnyObject) { }
2323
func fT<T>(_ t: T) { }
2424

2525
func testPassExistential(_ p: P, op: OP, opp: OP & P, cp: CP, sp: SP, any: Any, ao: AnyObject) {
2626
fP(p) // expected-error{{value of protocol type 'P' cannot conform to 'P'; only struct/enum/class types can conform to protocols}}
27-
fAO(p) // expected-error{{value of protocol type 'P' cannot conform to 'AnyObject'; only struct/enum/class types can conform to protocols}}
27+
fAO(p) // expected-error{{global function 'fAO' requires that 'P' be a class type}}
2828
fAOE(p) // expected-error{{argument type 'P' does not conform to expected type 'AnyObject'}}
2929
fT(p)
3030

@@ -33,13 +33,13 @@ func testPassExistential(_ p: P, op: OP, opp: OP & P, cp: CP, sp: SP, any: Any,
3333
fAOE(op)
3434
fT(op)
3535

36-
fAO(cp) // expected-error{{value of protocol type 'CP' cannot conform to 'AnyObject'; only struct/enum/class types can conform to protocols}}
36+
fAO(cp) // expected-error{{global function 'fAO' requires that 'CP' be a class type}}
3737
fAOE(cp)
3838
fT(cp)
3939

4040
fP(opp) // expected-error{{value of protocol type 'OP & P' cannot conform to 'P'; only struct/enum/class types can conform to protocols}}
4141
fOP(opp) // expected-error{{value of protocol type 'OP & P' cannot conform to 'OP'; only struct/enum/class types can conform to protocols}}
42-
fAO(opp) // expected-error{{value of protocol type 'OP & P' cannot conform to 'AnyObject'; only struct/enum/class types can conform to protocols}}
42+
fAO(opp) // expected-error{{global function 'fAO' requires that 'OP & P' be a class type}}
4343
fAOE(opp)
4444
fT(opp)
4545

test/type/subclass_composition.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ func dependentMemberTypes<T : BaseIntAndP2>(
299299
_: BaseIntAndP2.FullyConcrete) {}
300300

301301
func conformsToAnyObject<T : AnyObject>(_: T) {}
302-
// expected-note@-1 {{required by global function 'conformsToAnyObject' where 'T' = 'P1'}}
302+
// expected-note@-1 {{where 'T' = 'P1'}}
303303
func conformsToP1<T : P1>(_: T) {}
304304
// expected-note@-1 {{required by global function 'conformsToP1' where 'T' = 'P1'}}
305305
func conformsToP2<T : P2>(_: T) {}
@@ -411,7 +411,7 @@ func conformsTo<T1 : P2, T2 : Base<Int> & P2>(
411411

412412
// Errors
413413
conformsToAnyObject(p1)
414-
// expected-error@-1 {{value of protocol type 'P1' cannot conform to 'AnyObject'; only struct/enum/class types can conform to protocols}}
414+
// expected-error@-1 {{global function 'conformsToAnyObject' requires that 'P1' be a class type}}
415415

416416
conformsToP1(p1)
417417
// expected-error@-1 {{value of protocol type 'P1' cannot conform to 'P1'; only struct/enum/class types can conform to protocols}}

0 commit comments

Comments
 (0)