Skip to content

Commit bbbf4e7

Browse files
committed
[Sema] drop half-baked redundancy checking for now
We already don't diagnose all redundant requirements. Because inverses can be written in both inheritance and where clauses, but they're not treated uniformly in the implementation, it's a bit annoying to try and account for the redundancies in both places; `checkInheritanceClause` will go over the same "requirements" that we'll also check again in `swift::rewriting::expandDefaultRequirements`.
1 parent dcd465e commit bbbf4e7

File tree

4 files changed

+11
-26
lines changed

4 files changed

+11
-26
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2399,10 +2399,6 @@ ERROR(inferred_opaque_type,none,
23992399
// Inverse Constraints
24002400
ERROR(inverse_type_not_invertible,none,
24012401
"type %0 is not invertible", (Type))
2402-
ERROR(inverse_duplicate,none,
2403-
"duplicate inverse constraint", ())
2404-
NOTE(inverse_duplicate_previous,none,
2405-
"previous inverse constraint here", ())
24062402

24072403
// Extensions
24082404
ERROR(non_nominal_extension,none,

lib/Sema/TypeCheckDecl.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -952,21 +952,9 @@ bool HasNoncopyableAnnotationRequest::evaluate(Evaluator &evaluator, TypeDecl *d
952952

953953
// The set of defaults all types start with.
954954
auto defaults = InvertibleProtocolSet::full();
955-
std::map<InvertibleProtocolKind, SourceLoc> lastInverse;
956955

957-
// Does correctness checking after inspecting the inheritance clause.
958-
// TODO: we can probably move this to `checkInheritanceClause` instead.
959956
auto foundInverse = [&](SourceLoc loc, InvertibleProtocolKind kind) {
960-
// do we still have this default?
961-
if (defaults.contains(kind)) {
962-
defaults.remove(kind);
963-
lastInverse.insert({kind, loc});
964-
return;
965-
}
966-
967-
// diagnose duplicate inverses
968-
ctx.Diags.diagnose(loc, diag::inverse_duplicate);
969-
ctx.Diags.diagnose(lastInverse[kind], diag::inverse_duplicate_previous);
957+
defaults.remove(kind);
970958
};
971959

972960
// Check the inheritance clause for inverses.

test/Generics/inverse_protocols_errors.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,3 @@ struct NCThinger<T: ~Copyable>: ~Copyable, Hello {
4141
// expected-note@-3 {{add 'inout' for a mutable reference}}
4242
// expected-note@-4 {{add 'consuming' to take the value from the caller}}
4343
}
44-
45-
struct ExtraNoncopyStruct: ~Copyable, ~Copyable {}
46-
// expected-error@-1 {{duplicate inverse constraint}}
47-
// expected-note@-2 {{previous inverse constraint here}}
48-
49-
protocol ExtraNoncopyProto: ~Copyable, ~Copyable {}

test/Parse/inverses.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,17 @@ func blah<T>(_ t: borrowing T) where T: ~Copyable,
2424

2525
func foo<T: ~Copyable>(x: borrowing T) {}
2626

27-
struct Buurap<T: ~Copyable> {}
27+
struct Buurap<T: ~Copyable> where T: ~Copyable {}
2828

29-
protocol Foo: ~Copyable // expected-note {{previous inverse constraint here}}
30-
where Self: ~Copyable { // expected-error {{duplicate inverse constraint}}
29+
struct ExtraNoncopyStruct: ~Copyable, ~Copyable {}
30+
struct ExtraNoncopyEnum: ~Copyable, ~Copyable {}
31+
protocol ExtraNoncopyProto: ~Copyable, ~Copyable {}
32+
33+
protocol Foo: ~Copyable
34+
where Self: ~Copyable {
35+
36+
associatedtype Touch : ~Copyable,
37+
~Copyable
3138

3239
func test<T>(_ t: T) where T: ~Self // expected-error {{type 'Self' is not invertible}}
3340
}

0 commit comments

Comments
 (0)