Skip to content

Commit ad2e90a

Browse files
authored
Merge pull request #3734 from swiftwasm/main
2 parents b0540fe + 2dd50bb commit ad2e90a

File tree

7 files changed

+77
-5
lines changed

7 files changed

+77
-5
lines changed

docs/ReferenceGuides/UnderscoredAttributes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ even when `Self` is a reference type.
251251
```swift
252252
class C {
253253
func f() {}
254-
func g(_: @escaping () -> Void {
254+
func g(_: @escaping () -> Void) {
255255
g({ f() }) // error: call to method 'f' in closure requires explicit use of 'self'
256256
}
257257
func h(@_implicitSelfCapture _: @escaping () -> Void) {

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2964,6 +2964,9 @@ ERROR(broken_encodable_requirement,none,
29642964
"Encodable protocol is broken: unexpected requirement", ())
29652965
ERROR(broken_decodable_requirement,none,
29662966
"Decodable protocol is broken: unexpected requirement", ())
2967+
ERROR(codable_synthesis_empty_enum_not_supported,none,
2968+
"cannot automatically synthesize %0 conformance for empty enum %1",
2969+
(Type, Identifier))
29672970
ERROR(broken_differentiable_requirement,none,
29682971
"Differentiable protocol is broken: unexpected requirement", ())
29692972
WARNING(differentiable_nondiff_type_implicit_noderivative_fixit,none,

lib/Sema/DerivedConformances.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ bool DerivedConformance::checkAndDiagnoseDisallowedContext(
561561
return true;
562562
}
563563

564-
// A non-final class can't have an protocol-witnesss initializer in an
564+
// A non-final class can't have a protocol-witnesses initializer in an
565565
// extension.
566566
if (auto CD = dyn_cast<ClassDecl>(Nominal)) {
567567
if (!CD->isSemanticallyFinal() && isa<ConstructorDecl>(synthesizing) &&
@@ -573,6 +573,16 @@ bool DerivedConformance::checkAndDiagnoseDisallowedContext(
573573
}
574574
}
575575

576+
if (auto ED = dyn_cast<EnumDecl>(Nominal)) {
577+
if (ED->getAllCases().empty() &&
578+
(Protocol->isSpecificProtocol(KnownProtocolKind::Encodable) ||
579+
Protocol->isSpecificProtocol(KnownProtocolKind::Decodable))) {
580+
ED->diagnose(diag::codable_synthesis_empty_enum_not_supported,
581+
getProtocolType(), Nominal->getBaseIdentifier());
582+
return false;
583+
}
584+
}
585+
576586
return false;
577587
}
578588

stdlib/public/Concurrency/GlobalExecutor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ static constexpr size_t globalQueueCacheCount =
275275
static_cast<size_t>(JobPriority::UserInteractive) + 1;
276276
static std::atomic<dispatch_queue_t> globalQueueCache[globalQueueCacheCount];
277277

278-
#if defined(SWIFT_CONCURRENCY_BACK_DEPLOYMENT) || !defined(__apple__)
278+
#if defined(SWIFT_CONCURRENCY_BACK_DEPLOYMENT) || !defined(__APPLE__)
279279
extern "C" void dispatch_queue_set_width(dispatch_queue_t dq, long width);
280280
#endif
281281

@@ -295,7 +295,7 @@ static dispatch_queue_t getGlobalQueue(JobPriority priority) {
295295
if (SWIFT_LIKELY(queue))
296296
return queue;
297297

298-
#if defined(SWIFT_CONCURRENCY_BACK_DEPLOYMENT) || !defined(__apple__)
298+
#if defined(SWIFT_CONCURRENCY_BACK_DEPLOYMENT) || !defined(__APPLE__)
299299
const int DISPATCH_QUEUE_WIDTH_MAX_LOGICAL_CPUS = -3;
300300

301301
// Create a new cooperative concurrent queue and swap it in.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// RUN: %target-typecheck-verify-swift -enable-experimental-distributed -disable-availability-checking
2+
// REQUIRES: concurrency
3+
// REQUIRES: distributed
4+
5+
import _Distributed
6+
7+
// ==== ------------------------------------------------------------------------
8+
// MARK: Protocols
9+
10+
protocol LocalProto {
11+
func local()
12+
func localAsync() async
13+
func localAsyncThrows() async throws
14+
}
15+
16+
protocol WrongDistFuncs {
17+
distributed func notDistActor() // expected-error{{'distributed' function can only be declared within 'distributed actor'}}
18+
}
19+
20+
protocol MixedProto: DistributedActor {
21+
func local()
22+
func localAsync() async
23+
func localAsyncThrows() async throws
24+
25+
distributed func dist()
26+
distributed func distAsync() async
27+
distributed func distAsyncThrows() async throws
28+
}
29+
30+
protocol DistProto: DistributedActor {
31+
distributed func dist()
32+
distributed func distAsync() async
33+
distributed func distAsyncThrows() async throws
34+
}
35+
36+
// ==== ------------------------------------------------------------------------
37+
// MARK: Actors
38+
39+
distributed actor DA1: LocalProto {
40+
func local() {}
41+
// expected-error@-1{{actor-isolated instance method 'local()' cannot be used to satisfy a protocol requirement}}
42+
// expected-note@-2{{add 'nonisolated' to 'local()' to make this instance method not isolated to the actor}}
43+
func localAsync() async {}
44+
func localAsyncThrows() async throws {}
45+
}
46+

test/decl/protocol/special/coding/enum_codable_invalid_codingkeys.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
// Enums with a CodingKeys entity which is not a type should not derive
44
// conformance.
55
enum InvalidCodingKeys1 : Codable { // expected-error {{type 'InvalidCodingKeys1' does not conform to protocol 'Decodable'}}
6-
// expected-error@-1 {{type 'InvalidCodingKeys1' does not conform to protocol 'Encodable'}}
6+
// expected-error@-1 {{type 'InvalidCodingKeys1' does not conform to protocol 'Encodable'}}
7+
// expected-error@-2 {{cannot automatically synthesize 'Encodable' conformance for empty enum 'InvalidCodingKeys1'}}
8+
// expected-error@-3 {{cannot automatically synthesize 'Decodable' conformance for empty enum 'InvalidCodingKeys1'}}
79
static let CodingKeys = 5 // expected-note {{cannot automatically synthesize 'Decodable' because 'CodingKeys' is not an enum}}
810
// expected-note@-1 {{cannot automatically synthesize 'Encodable' because 'CodingKeys' is not an enum}}
911
}
@@ -12,6 +14,8 @@ enum InvalidCodingKeys1 : Codable { // expected-error {{type 'InvalidCodingKeys1
1214
// not derive conformance.
1315
enum InvalidCodingKeys2 : Codable { // expected-error {{type 'InvalidCodingKeys2' does not conform to protocol 'Decodable'}}
1416
// expected-error@-1 {{type 'InvalidCodingKeys2' does not conform to protocol 'Encodable'}}
17+
// expected-error@-2 {{cannot automatically synthesize 'Encodable' conformance for empty enum 'InvalidCodingKeys2'}}
18+
// expected-error@-3 {{cannot automatically synthesize 'Decodable' conformance for empty enum 'InvalidCodingKeys2'}}
1519
enum CodingKeys {} // expected-note {{cannot automatically synthesize 'Decodable' because 'CodingKeys' does not conform to CodingKey}}
1620
// expected-note@-1 {{cannot automatically synthesize 'Encodable' because 'CodingKeys' does not conform to CodingKey}}
1721
}
@@ -20,6 +24,8 @@ enum InvalidCodingKeys2 : Codable { // expected-error {{type 'InvalidCodingKeys2
2024
// conformance.
2125
enum InvalidCodingKeys3 : Codable { // expected-error {{type 'InvalidCodingKeys3' does not conform to protocol 'Decodable'}}
2226
// expected-error@-1 {{type 'InvalidCodingKeys3' does not conform to protocol 'Encodable'}}
27+
// expected-error@-2 {{cannot automatically synthesize 'Decodable' conformance for empty enum 'InvalidCodingKeys3'}}
28+
// expected-error@-3 {{cannot automatically synthesize 'Encodable' conformance for empty enum 'InvalidCodingKeys3'}}
2329
struct CodingKeys : CodingKey { // expected-note {{cannot automatically synthesize 'Decodable' because 'CodingKeys' is not an enum}}
2430
// expected-note@-1 {{cannot automatically synthesize 'Encodable' because 'CodingKeys' is not an enum}}
2531
var stringValue: String

test/decl/protocol/special/coding/enum_codable_simple.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,10 @@ let _ = SimpleEnum.CodingKeys.self // expected-error {{'CodingKeys' is inaccessi
4242
let _ = SimpleEnum.ACodingKeys.self // expected-error {{'ACodingKeys' is inaccessible due to 'private' protection level}}
4343
let _ = SimpleEnum.BCodingKeys.self // expected-error {{'BCodingKeys' is inaccessible due to 'private' protection level}}
4444
let _ = SimpleEnum.CCodingKeys.self // expected-error {{'CCodingKeys' is inaccessible due to 'private' protection level}}
45+
46+
// Empty enum must be diagnosed early, rather than leave the failure to DI.
47+
enum EmptyCodableEnum1: Encodable {} // expected-error{{cannot automatically synthesize 'Encodable' conformance for empty enum 'EmptyCodableEnum1'}}
48+
enum EmptyCodableEnum2: Decodable {} // expected-error{{cannot automatically synthesize 'Decodable' conformance for empty enum 'EmptyCodableEnum2'}}
49+
enum EmptyCodableEnum: Codable {}
50+
// expected-error@-1{{cannot automatically synthesize 'Encodable' conformance for empty enum 'EmptyCodableEnum'}}
51+
// expected-error@-2{{cannot automatically synthesize 'Decodable' conformance for empty enum 'EmptyCodableEnum'}}

0 commit comments

Comments
 (0)