Skip to content

Commit e81ffbd

Browse files
Merge pull request #80595 from AnthonyLatsis/no-curry-6.1
[6.1] TypeCheckType: Do not fail after emitting a warning
2 parents 9843a75 + 690e775 commit e81ffbd

File tree

4 files changed

+28
-26
lines changed

4 files changed

+28
-26
lines changed

lib/Sema/TypeCheckType.cpp

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -892,22 +892,7 @@ static Type applyGenericArguments(Type type,
892892
argTys.push_back(argTy);
893893
}
894894

895-
auto parameterized =
896-
ParameterizedProtocolType::get(ctx, protoType, argTys);
897-
898-
// FIXME: Can this not be done in ExistentialTypeSyntaxChecker?
899-
if (resolution.getOptions().isConstraintImplicitExistential() &&
900-
!ctx.LangOpts.hasFeature(Feature::ImplicitSome)) {
901-
diags
902-
.diagnose(loc, diag::existential_requires_any, parameterized,
903-
ExistentialType::get(parameterized),
904-
/*isAlias=*/isa<TypeAliasType>(type.getPointer()))
905-
.warnUntilSwiftVersion(7);
906-
907-
return ErrorType::get(ctx);
908-
}
909-
910-
return parameterized;
895+
return ParameterizedProtocolType::get(ctx, protoType, argTys);
911896
}
912897

913898
// Builtins have special handling.

test/type/explicit_existential.swift

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,13 @@ protocol Collection<T> {
159159
struct TestParameterizedProtocol<T> : Collection {
160160
typealias T = T
161161

162-
let x : Collection<T> // expected-warning {{use of protocol 'Collection<T>' as a type must be written 'any Collection<T>'}}
162+
let x : Collection<T> // expected-warning {{use of protocol 'Collection' as a type must be written 'any Collection'}}
163163
}
164164

165165
func acceptAny(_: Collection<Int>) {}
166-
// expected-warning@-1 {{use of protocol 'Collection<Int>' as a type must be written 'any Collection<Int>'}}
166+
// expected-warning@-1 {{use of protocol 'Collection' as a type must be written 'any Collection'}}
167167
func returnsAny() -> Collection<Int> {}
168-
// expected-warning@-1 {{use of protocol 'Collection<Int>' as a type must be written 'any Collection<Int>'}}
168+
// expected-warning@-1 {{use of protocol 'Collection' as a type must be written 'any Collection'}}
169169

170170
func testInvalidAny() {
171171
struct S: HasAssoc {
@@ -357,8 +357,8 @@ func testAnyFixIt() {
357357
let _: Optional<HasAssoc>
358358
// expected-warning@+1 {{constraint that suppresses conformance requires 'any'}}{{19-28=any ~Copyable}}
359359
let _: Optional<~Copyable>
360-
// FIXME: No fix-it + generic argument not diagnosed.
361-
// expected-warning@+1 {{use of protocol 'HasAssocGeneric<any HasAssoc>' as a type must be written 'any HasAssocGeneric<any HasAssoc>'}}{{none}}
360+
// expected-warning@+2:10 {{use of protocol 'HasAssocGeneric' as a type must be written 'any HasAssocGeneric'}}{{10-35=any HasAssocGeneric<HasAssoc>}}
361+
// expected-warning@+1:26 {{use of protocol 'HasAssoc' as a type must be written 'any HasAssoc'}}{{26-34=any HasAssoc}}
362362
let _: HasAssocGeneric<HasAssoc>
363363
// expected-warning@+1 {{use of protocol 'HasAssoc' as a type must be written 'any HasAssoc'}}{{14-22=any HasAssoc}}
364364
let _: S.G<HasAssoc>
@@ -390,8 +390,8 @@ func testAnyFixIt() {
390390
// expected-warning@+2 {{use of protocol 'HasAssoc' as a type must be written 'any HasAssoc'}}{{13-21=any HasAssoc}}
391391
// expected-warning@+1 {{constraint that suppresses conformance requires 'any'}}{{10-37=any ~G<HasAssoc>.Copyable_Alias}}
392392
let _: ~G<HasAssoc>.Copyable_Alias
393-
// FIXME: No fix-it + generic argument not diagnosed.
394-
// expected-warning@+1 {{use of 'HasAssocGeneric<any HasAssoc>' as a type must be written 'any HasAssocGeneric<any HasAssoc>}}{{none}}
393+
// expected-warning@+2:12 {{use of 'S.HasAssocGeneric_Alias' (aka 'HasAssocGeneric') as a type must be written 'any S.HasAssocGeneric_Alias' (aka 'any HasAssocGeneric')}} {{10-43=any S.HasAssocGeneric_Alias<HasAssoc>}}
394+
// expected-warning@+1:34 {{use of protocol 'HasAssoc' as a type must be written 'any HasAssoc'}}{{34-42=any HasAssoc}}
395395
let _: S.HasAssocGeneric_Alias<HasAssoc>
396396
// FIXME: No diagnostic.
397397
let _: HasAssoc.Int_Alias
@@ -525,6 +525,8 @@ func testAnyFixIt() {
525525

526526
// expected-error@+1 {{optional 'any' type must be written '(any HasAssoc)?'}}{{10-23=(any HasAssoc)?}}
527527
let _: any HasAssoc?
528+
// expected-error@+1:10 {{optional 'any' type must be written '(any HasAssocGeneric<Int>)?'}}{{10-35=(any HasAssocGeneric<Int>)?}}
529+
let _: any HasAssocGeneric<Int>?
528530
// FIXME: Better recovery
529531
// expected-error@+1 {{type '(any Copyable)?' cannot be suppressed}}
530532
let _: any ~Copyable?

test/type/parameterized_existential.swift

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ protocol Sequence<Element> { // expected-note {{'Sequence' declared here}}
77
// 'any' is required here
88

99
func takesSequenceOfInt1(_: Sequence<Int>) {}
10-
// expected-warning@-1 {{use of protocol 'Sequence<Int>' as a type must be written 'any Sequence<Int>'}}
10+
// expected-warning@-1 {{use of protocol 'Sequence' as a type must be written 'any Sequence'}}
1111

1212
func returnsSequenceOfInt1() -> Sequence<Int> {}
13-
// expected-warning@-1 {{use of protocol 'Sequence<Int>' as a type must be written 'any Sequence<Int>'}}
13+
// expected-warning@-1 {{use of protocol 'Sequence' as a type must be written 'any Sequence'}}
1414

1515
struct ConcreteSequence<Element> : Sequence {}
1616

@@ -74,7 +74,7 @@ func saturation(_ dry: any Sponge, _ wet: any Sponge<Int, Int>) {
7474

7575
func typeExpr() {
7676
_ = Sequence<Int>.self
77-
// expected-warning@-1 {{use of protocol 'Sequence<Int>' as a type must be written 'any Sequence<Int>'}}
77+
// expected-warning@-1 {{use of protocol 'Sequence' as a type must be written 'any Sequence'}}
7878

7979
_ = any Sequence<Int>.self
8080
// expected-error@-1 {{'self' is not a member type of protocol 'parameterized_existential.Sequence<Swift.Int>'}}
@@ -103,3 +103,12 @@ func genericIncrement<T: Numeric>(_ n : any Collection<T>) {
103103
_ = value + 1
104104
}
105105
}
106+
107+
protocol TextContainerViewProtocol {
108+
// expected-error@+1 {{optional 'any' type must be written '(any TextContainerViewDelegate<Self>)?'}}
109+
var delegate: any TextContainerViewDelegate<Self>? { get set}
110+
}
111+
112+
protocol TextContainerViewDelegate<View> {
113+
associatedtype View: TextContainerViewProtocol
114+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// RUN: %target-typecheck-verify-swift -target %target-swift-5.7-abi-triple
2+
3+
// expected-warning@+1 {{use of protocol 'Collection' as a type must be written 'any Collection'; this will be an error in a future Swift language mode}}
4+
func test(c: Collection<Int>) -> Int {
5+
c.count
6+
}

0 commit comments

Comments
 (0)