Skip to content

Commit 2fad7ca

Browse files
committed
Sema: Implement adoption mode for ExistentialAny
1 parent 086bb4c commit 2fad7ca

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

Diff for: lib/Sema/TypeCheckType.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -6497,7 +6497,15 @@ class ExistentialTypeSyntaxChecker : public ASTWalker {
64976497
/*isAlias=*/isa<TypeAliasDecl>(decl)));
64986498
}
64996499

6500-
diag->warnUntilSwiftVersion(7);
6500+
// If the feature is enabled in adoption mode, warn unconditionally.
6501+
// Otherwise, until Swift 7.
6502+
if (Ctx.LangOpts.getFeatureState(Feature::ExistentialAny)
6503+
.isEnabledForAdoption()) {
6504+
diag->limitBehavior(DiagnosticBehavior::Warning);
6505+
} else {
6506+
diag->warnUntilSwiftVersion(7);
6507+
}
6508+
65016509
emitInsertAnyFixit(*diag, T);
65026510
}
65036511

Diff for: test/type/explicit_existential.swift

+24-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
1-
// RUN: %target-typecheck-verify-swift -verify-additional-prefix default-swift-mode-
2-
// RUN: %target-typecheck-verify-swift -swift-version 6 -verify-additional-prefix swift-6-
3-
// RUN: %target-typecheck-verify-swift -enable-upcoming-feature ExistentialAny -verify-additional-prefix explicit-any- -verify-additional-prefix default-swift-mode-
4-
// RUN: %target-typecheck-verify-swift -enable-experimental-feature ExistentialAny -verify-additional-prefix explicit-any- -verify-additional-prefix default-swift-mode-
1+
// RUN: %target-typecheck-verify-swift \
2+
// RUN: -verify-additional-prefix default-swift-mode-
3+
4+
// RUN: %target-typecheck-verify-swift -swift-version 6 \
5+
// RUN: -verify-additional-prefix swift-6-
6+
7+
// RUN: %target-typecheck-verify-swift -enable-upcoming-feature ExistentialAny \
8+
// RUN: -verify-additional-prefix default-swift-mode- \
9+
// RUN: -verify-additional-prefix explicit-any-
10+
11+
// RUN: %target-typecheck-verify-swift -enable-upcoming-feature ExistentialAny:adoption \
12+
// To verify that the message is not followed by
13+
// "; this will be an error ...".
14+
// RUN: -print-diagnostic-groups \
15+
// RUN: -verify-additional-prefix default-swift-mode- \
16+
// RUN: -verify-additional-prefix explicit-any-adopt-
517

618
// REQUIRES: swift_feature_ExistentialAny
719

@@ -20,8 +32,10 @@ protocol Bar {
2032
class Bistro {
2133
convenience init(_: Bar){ self.init()}
2234
// expected-explicit-any-warning@-1 {{use of protocol 'Bar' as a type must be written 'any Bar'; this will be an error in a future Swift language mode}}{{23-26=any Bar}}
35+
// expected-explicit-any-adopt-warning@-2 {{use of protocol 'Bar' as a type must be written 'any Bar' [ExistentialAny]}}{{23-26=any Bar}}
2336
class func returnBar() -> Bar {}
2437
// expected-explicit-any-warning@-1 {{use of protocol 'Bar' as a type must be written 'any Bar'; this will be an error in a future Swift language mode}}{{29-32=any Bar}}
38+
// expected-explicit-any-adopt-warning@-2 {{use of protocol 'Bar' as a type must be written 'any Bar' [ExistentialAny]}}{{29-32=any Bar}}
2539
}
2640

2741
func useBarAsType(_ x: any Bar) {}
@@ -221,6 +235,7 @@ enum E1: RawRepresentable {
221235

222236
var rawValue: P1 {
223237
// expected-explicit-any-warning@-1 {{use of protocol 'P1' as a type must be written 'any P1'; this will be an error in a future Swift language mode}}{{17-19=any P1}}
238+
// expected-explicit-any-adopt-warning@-2 {{use of protocol 'P1' as a type must be written 'any P1' [ExistentialAny]}}{{17-19=any P1}}
224239
return ConcreteComposition()
225240
}
226241
}
@@ -318,8 +333,10 @@ enum EE : Equatable, any Empty { // expected-error {{raw type 'any Empty' is not
318333

319334
// Protocols from a serialized module (the standard library).
320335
do {
336+
// expected-explicit-any-adopt-warning@+2 {{use of protocol 'Decodable' as a type must be written 'any Decodable' [ExistentialAny]}}
321337
// expected-explicit-any-warning@+1 {{use of protocol 'Decodable' as a type must be written 'any Decodable'; this will be an error in a future Swift language mode}}
322338
let _: Decodable
339+
// expected-explicit-any-adopt-warning@+2 {{use of 'Codable' (aka 'Decodable & Encodable') as a type must be written 'any Codable' (aka 'any Decodable & Encodable') [ExistentialAny]}}
323340
// expected-explicit-any-warning@+1 {{use of 'Codable' (aka 'Decodable & Encodable') as a type must be written 'any Codable' (aka 'any Decodable & Encodable'); this will be an error in a future Swift language mode}}
324341
let _: Codable
325342
}
@@ -547,6 +564,7 @@ func testEnumAssociatedValue() {
547564
case c1((any HasAssoc) -> Void)
548565
// expected-warning@+1 {{use of protocol 'HasAssoc' as a type must be written 'any HasAssoc'}}
549566
case c2((HasAssoc) -> Void)
567+
// expected-explicit-any-adopt-warning@+2 {{use of protocol 'P' as a type must be written 'any P' [ExistentialAny]}}
550568
// expected-explicit-any-warning@+1 {{use of protocol 'P' as a type must be written 'any P'; this will be an error in a future Swift language mode}}
551569
case c3((P) -> Void)
552570
}
@@ -574,5 +592,7 @@ func f(_ x: Objectlike) {}
574592
typealias Copy = Copyable
575593
func h(_ z1: Copy,
576594
// expected-explicit-any-warning@-1 {{use of 'Copy' (aka 'Copyable') as a type must be written 'any Copy' (aka 'any Copyable'); this will be an error in a future Swift language mode}}
595+
// expected-explicit-any-adopt-warning@-2 {{use of 'Copy' (aka 'Copyable') as a type must be written 'any Copy' (aka 'any Copyable') [ExistentialAny]}}
577596
_ z2: Copyable) {}
578597
// expected-explicit-any-warning@-1 {{use of protocol 'Copyable' as a type must be written 'any Copyable'; this will be an error in a future Swift language mode}}
598+
// expected-explicit-any-adopt-warning@-2 {{use of protocol 'Copyable' as a type must be written 'any Copyable' [ExistentialAny]}}

0 commit comments

Comments
 (0)