You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TypeCheckType: Unconditionally warn about missing existential any until Swift 7
#72659 turned out to have some
source compatibility fallout that we need to fix. Instead of introducing
yet another brittle compatibility hack, stop emitting errors about a
missing `any` altogether until a future language mode.
Besides resolving the compatibility issue, this will encourage
developers to adopt any sooner and grant us ample time to gracefully
address any remaining bugs before the source compatibility burden
resurfaces.
A subsequent commit adds a diagnostic group that will allow users to
escalate these warnings to errors with `-Werror ExistentialAny`.
Copy file name to clipboardExpand all lines: test/Generics/inverse_generics.swift
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -471,8 +471,8 @@ func checkExistentials() {
471
471
472
472
typealias NotCopyable =~Copyable
473
473
typealias EmptyComposition =~Copyable &~Escapable
474
-
func test(_ t:borrowingNotCopyable){} // expected-error {{use of 'NotCopyable' (aka '~Copyable') as a type must be written 'any NotCopyable'}}
475
-
func test(_ t:borrowingEmptyComposition){} // expected-error {{use of 'EmptyComposition' (aka '~Copyable & ~Escapable') as a type must be written 'any EmptyComposition' (aka 'any ~Copyable & ~Escapable')}}
474
+
func test(_ t:borrowingNotCopyable){} // expected-warning {{use of 'NotCopyable' (aka '~Copyable') as a type must be written 'any NotCopyable'}}
475
+
func test(_ t:borrowingEmptyComposition){} // expected-warning {{use of 'EmptyComposition' (aka '~Copyable & ~Escapable') as a type must be written 'any EmptyComposition' (aka 'any ~Copyable & ~Escapable')}}
Copy file name to clipboardExpand all lines: test/Macros/top_level_freestanding.swift
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -107,12 +107,12 @@ func testGlobalVariable() {
107
107
108
108
// expected-note @+1 6 {{in expansion of macro 'anonymousTypes' here}}
109
109
#anonymousTypes(causeErrors:true){"foo"}
110
-
// DIAG_BUFFERS-DAG: @__swiftmacro_9MacroUser0033top_level_freestandingswift_DbGHjfMX108_0_33_082AE7CFEFA6960C804A9FE7366EB5A0Ll14anonymousTypesfMf0_{{.*}}: error: use of protocol 'Equatable' as a type must be written 'any Equatable'
111
-
// DIAG_BUFFERS-DAG: @__swiftmacro_9MacroUser00142___swiftmacro_9MacroUser0033top_level_freestandingswift_DbGHjfMX108_0_33_082AE7CFEFA6960C804A9FE7366EB5A0Ll14anonymousTypesfMf0_swift_DAIABdjIbfMX23_2_33_082AE7CFEFA6960C804A9FE7366EB5A0Ll27introduceTypeCheckingErrorsfMf_{{.*}}: error: use of protocol 'Hashable' as a type must be written 'any Hashable'
110
+
// DIAG_BUFFERS-DAG: @__swiftmacro_9MacroUser0033top_level_freestandingswift_DbGHjfMX108_0_33_082AE7CFEFA6960C804A9FE7366EB5A0Ll14anonymousTypesfMf0_{{.*}}: warning: use of protocol 'Equatable' as a type must be written 'any Equatable'
111
+
// DIAG_BUFFERS-DAG: @__swiftmacro_9MacroUser00142___swiftmacro_9MacroUser0033top_level_freestandingswift_DbGHjfMX108_0_33_082AE7CFEFA6960C804A9FE7366EB5A0Ll14anonymousTypesfMf0_swift_DAIABdjIbfMX23_2_33_082AE7CFEFA6960C804A9FE7366EB5A0Ll27introduceTypeCheckingErrorsfMf_{{.*}}: warning: use of protocol 'Hashable' as a type must be written 'any Hashable'
112
112
113
113
// expected-note @+1 2 {{in expansion of macro 'anonymousTypes' here}}
114
114
#anonymousTypes {()->Stringin
115
-
// expected-error @+1 {{use of protocol 'Equatable' as a type must be written 'any Equatable'}}
115
+
// expected-warning @+1 {{use of protocol 'Equatable' as a type must be written 'any Equatable'}}
Copy file name to clipboardExpand all lines: test/decl/protocol/existential_member_accesses_self_assoctype_fixit.swift
+8-8Lines changed: 8 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -12,12 +12,12 @@ protocol P {
12
12
protocolQ{}
13
13
14
14
do{
15
-
func test(p:P){ // expected-error {{use of protocol 'P' as a type must be written 'any P'}}
15
+
func test(p:P){ // expected-warning {{use of protocol 'P' as a type must be written 'any P'}}
16
16
p.method(false) // expected-error {{member 'method' cannot be used on value of type 'any P'; consider using a generic constraint instead}} {{-1:16--1:17=some P}} {{none}}
17
17
}
18
18
}
19
19
do{
20
-
func test(p:((P))){ // expected-error {{use of protocol 'P' as a type must be written 'any P'}}
20
+
func test(p:((P))){ // expected-warning {{use of protocol 'P' as a type must be written 'any P'}}
21
21
p.method(false) // expected-error {{member 'method' cannot be used on value of type 'any P'; consider using a generic constraint instead}} {{-1:18--1:19=some P}} {{none}}
22
22
}
23
23
}
@@ -57,12 +57,12 @@ do {
57
57
}
58
58
}
59
59
do{
60
-
func test(p:P.Type){ // expected-error {{use of protocol 'P' as a type must be written 'any P'}}
60
+
func test(p:P.Type){ // expected-warning {{use of protocol 'P' as a type must be written 'any P'}}
61
61
p.staticMethod(false) // expected-error {{member 'staticMethod' cannot be used on value of type 'any P.Type'; consider using a generic constraint instead}} {{-1:16--1:17=(some P)}} {{none}}
62
62
}
63
63
}
64
64
do{
65
-
func test(p:(P).Type){ // expected-error {{use of protocol 'P' as a type must be written 'any P'}}
65
+
func test(p:(P).Type){ // expected-warning {{use of protocol 'P' as a type must be written 'any P'}}
66
66
p.staticMethod(false) // expected-error {{member 'staticMethod' cannot be used on value of type 'any P.Type'; consider using a generic constraint instead}} {{-1:17--1:18=some P}} {{none}}
67
67
}
68
68
}
@@ -78,12 +78,12 @@ do {
78
78
}
79
79
80
80
do{
81
-
func test(p:P&Q){ // expected-error {{use of protocol 'P' as a type must be written 'any P'}}
81
+
func test(p:P&Q){ // expected-warning {{use of protocol 'P' as a type must be written 'any P'}}
82
82
p.method(false) // expected-error {{member 'method' cannot be used on value of type 'any P & Q'; consider using a generic constraint instead}} {{-1:16--1:21=some P & Q}} {{none}}
83
83
}
84
84
}
85
85
do{
86
-
func test(p:((P&Q))){ // expected-error {{use of protocol 'P' as a type must be written 'any P'}}
86
+
func test(p:((P&Q))){ // expected-warning {{use of protocol 'P' as a type must be written 'any P'}}
87
87
p.method(false) // expected-error {{member 'method' cannot be used on value of type 'any P & Q'; consider using a generic constraint instead}} {{-1:18--1:23=some P & Q}} {{none}}
88
88
}
89
89
}
@@ -123,12 +123,12 @@ do {
123
123
}
124
124
}
125
125
do{
126
-
func test(p:(P&Q).Type){ // expected-error {{use of protocol 'P' as a type must be written 'any P'}}
126
+
func test(p:(P&Q).Type){ // expected-warning {{use of protocol 'P' as a type must be written 'any P'}}
127
127
p.staticMethod(false) // expected-error {{member 'staticMethod' cannot be used on value of type 'any (P & Q).Type'; consider using a generic constraint instead}} {{-1:17--1:22=some P & Q}} {{none}}
128
128
}
129
129
}
130
130
do{
131
-
func test(p:((P&Q)).Type){ // expected-error {{use of protocol 'P' as a type must be written 'any P'}}
131
+
func test(p:((P&Q)).Type){ // expected-warning {{use of protocol 'P' as a type must be written 'any P'}}
132
132
p.staticMethod(false) // expected-error {{member 'staticMethod' cannot be used on value of type 'any (P & Q).Type'; consider using a generic constraint instead}} {{-1:18--1:23=some P & Q}} {{none}}
// expected-warning@-1 {{checking a value with optional type 'T?' against type 'any P1' succeeds whenever the value is non-nil; did you mean to use '!= nil'?}}
476
476
}
477
477
func j(_ x :C1)->Bool{
478
-
return x is P1 // expected-error {{use of protocol 'P1' as a type must be written 'any P1'}}
478
+
return x is P1 // expected-warning {{use of protocol 'P1' as a type must be written 'any P1'}}
vardelegate:AsExistentialAssocTypeB?{get} // expected-error {{use of protocol 'AsExistentialAssocTypeB' as a type must be written 'any AsExistentialAssocTypeB'}}
func aMethod(_ object :AsExistentialAssocTypeAgainA) // expected-error {{use of protocol 'AsExistentialAssocTypeAgainA' as a type must be written 'any AsExistentialAssocTypeAgainA'}}
0 commit comments