Skip to content

Commit d5814ae

Browse files
committed
[RequirementMachine] Only emit a redundancy warning for layout constraints
if the type is constrained to a class layout, and add a few more test cases for type requirement conflicts.
1 parent a992917 commit d5814ae

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/AST/RequirementMachine/RequirementLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ static void desugarLayoutRequirement(Type subjectType,
152152
if (!subjectType->isTypeParameter()) {
153153
Requirement requirement(RequirementKind::Layout,
154154
subjectType, layout);
155-
if (subjectType->isAnyClassReferenceType()) {
155+
if (layout->isClass() && subjectType->isAnyClassReferenceType()) {
156156
errors.push_back(
157157
RequirementError::forRedundantRequirement(requirement, loc));
158158
} else {

test/Generics/requirement_machine_diagnostics.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,17 @@ class C {}
5959
func concreteLayoutRedundancy<T>(_: T) where C : AnyObject {}
6060
// expected-warning@-1{{redundant constraint 'C' : 'AnyObject'}}
6161

62+
func concreteLayoutConflict<T>(_: T) where Int : AnyObject {}
63+
// expected-error@-1{{type 'Int' in conformance requirement does not refer to a generic parameter or associated type}}
64+
6265
class C2: C {}
6366
func concreteSubclassRedundancy<T>(_: T) where C2 : C {}
6467
// expected-warning@-1{{redundant superclass constraint 'C2' : 'C'}}
6568

69+
class D {}
70+
func concreteSubclassConflict<T>(_: T) where D : C {}
71+
// expected-error@-1{{type 'D' in conformance requirement does not refer to a generic parameter or associated type}}
72+
6673
protocol UselessProtocolWhereClause where Int == Int {}
6774
// expected-warning@-1 {{redundant same-type constraint 'Int' == 'Int'}}
6875

0 commit comments

Comments
 (0)