Skip to content

Commit 637e2d4

Browse files
committed
[Diagnostics] Update existential type error message for clarity
Rework solution to be squashed
1 parent 63b2290 commit 637e2d4

File tree

4 files changed

+6
-7
lines changed

4 files changed

+6
-7
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4793,7 +4793,7 @@ ERROR(unchecked_not_existential,none,
47934793
"'unchecked' attribute cannot apply to non-protocol type %0", (Type))
47944794

47954795
ERROR(redundant_any_in_existential,none,
4796-
"redundant 'any' has no effect on existential type %0",
4796+
"redundant 'any' in type %0",
47974797
(Type))
47984798
ERROR(any_not_existential,none,
47994799
"'any' has no effect on %select{concrete type|type parameter}0 %1",

lib/AST/ASTContext.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4316,8 +4316,6 @@ Type ExistentialType::get(Type constraint) {
43164316
if (constraint->is<ExistentialMetatypeType>())
43174317
return constraint;
43184318

4319-
assert(constraint->isConstraintType());
4320-
43214319
bool printWithAny = true;
43224320
if (constraint->isEqual(C.TheAnyType) || constraint->isAnyObject())
43234321
printWithAny = false;

lib/Sema/TypeCheckType.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4237,7 +4237,8 @@ TypeResolver::resolveExistentialType(ExistentialTypeRepr *repr,
42374237
// Diagnose redundant `any` on an already existential type e.g. any (any P)
42384238
// with a fix-it to remove first any.
42394239
if (constraintType->is<ExistentialType>()) {
4240-
diagnose(repr->getLoc(), diag::redundant_any_in_existential, constraintType)
4240+
diagnose(repr->getLoc(), diag::redundant_any_in_existential,
4241+
ExistentialType::get(constraintType))
42414242
.fixItRemove(repr->getAnyLoc());
42424243
return constraintType;
42434244
}

test/type/explicit_existential.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,12 +334,12 @@ func testEnumAssociatedValue() {
334334

335335
// https://github.com/apple/swift/issues/58920
336336
typealias Iterator = any IteratorProtocol
337-
var example: any Iterator = 5 // expected-error{{redundant 'any' has no effect on existential type 'Iterator' (aka 'any IteratorProtocol')}} {{14-18=}}
337+
var example: any Iterator = 5 // expected-error{{redundant 'any' in type 'any Iterator' (aka 'any any IteratorProtocol')}} {{14-18=}}
338338
// expected-error@-1{{value of type 'Int' does not conform to specified type 'IteratorProtocol'}}
339-
var example1: any (any IteratorProtocol) = 5 // expected-error{{redundant 'any' has no effect on existential type 'any IteratorProtocol'}} {{15-19=}}
339+
var example1: any (any IteratorProtocol) = 5 // expected-error{{redundant 'any' in type 'any (any IteratorProtocol)'}} {{15-19=}}
340340
// expected-error@-1{{value of type 'Int' does not conform to specified type 'IteratorProtocol'}}
341341

342342
protocol PP {}
343343
struct A : PP {}
344344
let _: any PP = A() // Ok
345-
let _: any (any PP) = A() // expected-error{{redundant 'any' has no effect on existential type 'any PP'}} {{8-12=}}
345+
let _: any (any PP) = A() // expected-error{{redundant 'any' in type 'any (any PP)'}} {{8-12=}}

0 commit comments

Comments
 (0)