Skip to content

Commit

Permalink
ExistentialTypeSyntaxChecker: Fix any fix-it for IUO
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyLatsis committed Apr 25, 2024
1 parent 7dc65a3 commit 6aca4f2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Sema/TypeCheckType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5995,6 +5995,7 @@ class ExistentialTypeSyntaxChecker : public ASTWalker {
static bool anySyntaxNeedsParens(TypeRepr *parent) {
switch (parent->getKind()) {
case TypeReprKind::Optional:
case TypeReprKind::ImplicitlyUnwrappedOptional:
case TypeReprKind::Protocol:
return true;
case TypeReprKind::Metatype:
Expand All @@ -6009,7 +6010,6 @@ class ExistentialTypeSyntaxChecker : public ASTWalker {
case TypeReprKind::UnqualifiedIdent:
case TypeReprKind::QualifiedIdent:
case TypeReprKind::Dictionary:
case TypeReprKind::ImplicitlyUnwrappedOptional:
case TypeReprKind::Inverse:
case TypeReprKind::Tuple:
case TypeReprKind::Fixed:
Expand Down
7 changes: 7 additions & 0 deletions test/type/explicit_existential.swift
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,13 @@ func testAnyFixIt() {
let _: (HasAssoc)?
// expected-error@+1 {{constraint that suppresses conformance requires 'any'}}{{11-20=any ~Copyable}}
let _: (~Copyable)?
// expected-error@+1 {{use of protocol 'HasAssoc' as a type must be written 'any HasAssoc'}}{{10-18=(any HasAssoc)}}
let _: HasAssoc!
// expected-error@+2 {{type '(any Copyable)?' cannot be suppressed}}
// expected-warning@+1 {{using '!' is not allowed here; treating this as '?' instead}}
let _: ~Copyable!
// expected-error@+1 {{constraint that suppresses conformance requires 'any'}}{{11-20=any ~Copyable}}
let _: (~Copyable)!
// expected-error@+1 {{use of protocol 'HasAssoc' as a type must be written 'any HasAssoc'}}{{10-23=(any HasAssoc.Type)}}
let _: HasAssoc.Type?
// expected-error@+1 {{constraint that suppresses conformance requires 'any'}}{{10-26=(any (~Copyable).Type)}}
Expand Down
7 changes: 7 additions & 0 deletions test/type/explicit_existential_swift6.swift
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,13 @@ func testAnyFixIt() {
let _: (HasAssoc)?
// expected-error@+1 {{constraint that suppresses conformance requires 'any'}}{{11-20=any ~Copyable}}
let _: (~Copyable)?
// expected-error@+1 {{use of protocol 'HasAssoc' as a type must be written 'any HasAssoc'}}{{10-18=(any HasAssoc)}}
let _: HasAssoc!
// expected-error@+2 {{type '(any Copyable)?' cannot be suppressed}}
// expected-warning@+1 {{using '!' is not allowed here; treating this as '?' instead}}
let _: ~Copyable!
// expected-error@+1 {{constraint that suppresses conformance requires 'any'}}{{11-20=any ~Copyable}}
let _: (~Copyable)!
// expected-error@+1 {{use of protocol 'HasAssoc' as a type must be written 'any HasAssoc'}}{{10-23=(any HasAssoc.Type)}}
let _: HasAssoc.Type?
// expected-error@+1 {{constraint that suppresses conformance requires 'any'}}{{10-26=(any (~Copyable).Type)}}
Expand Down

0 comments on commit 6aca4f2

Please sign in to comment.