Skip to content

Commit e6dc7e6

Browse files
committed
[RequirementMachine] Emit diagnostics for structural requirements in protocol
and typealias requirement signatures.
1 parent ec45d96 commit e6dc7e6

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

lib/AST/RequirementMachine/RequirementLowering.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,8 @@ StructuralRequirementsRequest::evaluate(Evaluator &evaluator,
720720
}
721721
}
722722

723+
diagnoseRequirementErrors(ctx, errors, /*allowConcreteGenericParams=*/false);
724+
723725
return ctx.AllocateCopy(result);
724726
}
725727

@@ -974,6 +976,8 @@ TypeAliasRequirementsRequest::evaluate(Evaluator &evaluator,
974976
}
975977
}
976978

979+
diagnoseRequirementErrors(ctx, errors, /*allowConcreteGenericParams=*/false);
980+
977981
return ctx.AllocateCopy(result);
978982
}
979983

test/Generics/requirement_machine_diagnostics.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,12 @@ func concreteLayoutRedundancy<T>(_: T) where C : AnyObject {}
6262
class C2: C {}
6363
func concreteSubclassRedundancy<T>(_: T) where C2 : C {}
6464
// expected-warning@-1{{redundant superclass constraint 'C2' : 'C'}}
65+
66+
protocol UselessProtocolWhereClause where Int == Int {}
67+
// expected-warning@-1 {{redundant same-type constraint 'Int' == 'Int'}}
68+
69+
protocol InvalidProtocolWhereClause where Self: Int {}
70+
// expected-error@-1 {{type 'Self' constrained to non-protocol, non-class type 'Int'}}
71+
72+
typealias Alias<T> = T where Int == Int
73+
// expected-warning@-1 {{redundant same-type constraint 'Int' == 'Int'}}

0 commit comments

Comments
 (0)