Skip to content

Commit 01b0fa0

Browse files
Merge pull request #60390 from mazevedofs/existential-error-message
[Diagnostics] Update existential type error message for clarity
2 parents 3c4cd58 + 68687a6 commit 01b0fa0

File tree

5 files changed

+9
-10
lines changed

5 files changed

+9
-10
lines changed

include/swift/AST/DiagnosticsSema.def

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

48014801
ERROR(redundant_any_in_existential,none,
4802-
"redundant 'any' has no effect on existential type %0",
4802+
"redundant 'any' in type %0",
48034803
(Type))
48044804
ERROR(any_not_existential,none,
48054805
"'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
@@ -4325,8 +4325,6 @@ Type ExistentialType::get(Type constraint) {
43254325
if (constraint->is<ExistentialMetatypeType>())
43264326
return constraint;
43274327

4328-
assert(constraint->isConstraintType());
4329-
43304328
bool printWithAny = true;
43314329
if (constraint->isEqual(C.TheAnyType) || constraint->isAnyObject())
43324330
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=}}

test/type/explicit_existential_swift6.swift

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

361361
// https://github.com/apple/swift/issues/58920
362362
typealias Iterator = any IteratorProtocol
363-
var example: any Iterator = 5 // expected-error{{redundant 'any' has no effect on existential type 'Iterator' (aka 'any IteratorProtocol')}} {{14-18=}}
363+
var example: any Iterator = 5 // expected-error{{redundant 'any' in type 'any Iterator' (aka 'any any IteratorProtocol')}} {{14-18=}}
364364
// expected-error@-1{{value of type 'Int' does not conform to specified type 'IteratorProtocol'}}
365-
var example1: any (any IteratorProtocol) = 5 // expected-error{{redundant 'any' has no effect on existential type 'any IteratorProtocol'}} {{15-19=}}
365+
var example1: any (any IteratorProtocol) = 5 // expected-error{{redundant 'any' in type 'any (any IteratorProtocol)'}} {{15-19=}}
366366
// expected-error@-1{{value of type 'Int' does not conform to specified type 'IteratorProtocol'}}
367367

368368
protocol PP {}
369369
struct A : PP {}
370370
let _: any PP = A() // Ok
371-
let _: any (any PP) = A() // expected-error{{redundant 'any' has no effect on existential type 'any PP'}} {{8-12=}}
371+
let _: any (any PP) = A() // expected-error{{redundant 'any' in type 'any (any PP)'}} {{8-12=}}

0 commit comments

Comments
 (0)