Skip to content

Commit 66e3110

Browse files
authored
Merge pull request #73635 from ktoso/wip-relax-macro-diagnostics
2 parents 6e6a5ba + b77685e commit 66e3110

4 files changed

+35
-11
lines changed

lib/Macros/Sources/SwiftMacros/DistributedResolvableMacro.swift

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,6 @@ extension DistributedResolvableMacro {
133133
var isGenericStub = false
134134
var specificActorSystemRequirement: TypeSyntax?
135135

136-
if proto.genericWhereClause == nil {
137-
throw DiagnosticsError(
138-
syntax: node,
139-
message: """
140-
Distributed protocol must declare actor system with SerializationRequirement, for example:
141-
protocol Greeter<ActorSystem>: DistributedActor where ActorSystem: DistributedActorSystem<any Codable>
142-
""", id: .invalidApplication)
143-
}
144-
145136
let accessModifiers = proto.accessControlModifiers
146137

147138
for req in proto.genericWhereClause?.requirements ?? [] {

test/Distributed/Macros/distributed_macro_expansion_DistributedProtocol_errors.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ distributed actor Caplin {
2626
typealias ActorSystem = FakeActorSystem
2727
}
2828

29-
@Resolvable // expected-error{{Distributed protocol must declare actor system with SerializationRequirement}}
29+
@Resolvable // expected-note 3{{in expansion of macro 'Resolvable' on protocol 'Fail' here}}
3030
protocol Fail: DistributedActor {
3131
distributed func method() -> String
3232
}
@@ -35,7 +35,6 @@ protocol Fail: DistributedActor {
3535
public protocol SomeRoot: DistributedActor, Sendable
3636
where ActorSystem: DistributedActorSystem<any Codable> {
3737

38-
// TODO(distributed): we could diagnose this better?
3938
associatedtype AssociatedSomething: Sendable // expected-note{{protocol requires nested type 'AssociatedSomething'; add nested type 'AssociatedSomething' for conformance}}
4039
static var staticValue: String { get }
4140
var value: String { get }
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// REQUIRES: swift_swift_parser, asserts
2+
//
3+
// UNSUPPORTED: back_deploy_concurrency
4+
// REQUIRES: concurrency
5+
// REQUIRES: distributed
6+
//
7+
// RUN: %empty-directory(%t)
8+
// RUN: %empty-directory(%t-scratch)
9+
10+
// RUN: %target-swift-frontend-emit-module -emit-module-path %t/FakeDistributedActorSystems.swiftmodule -module-name FakeDistributedActorSystems -disable-availability-checking %S/../Inputs/FakeDistributedActorSystems.swift
11+
// RUN: not %target-swift-frontend -typecheck -disable-availability-checking -plugin-path %swift-plugin-dir -parse-as-library -I %t %S/../Inputs/FakeDistributedActorSystems.swift -dump-macro-expansions %s 2>&1 | %FileCheck %s
12+
13+
import Distributed
14+
15+
// These tests check the error output inside of a "bad" expansion;
16+
//
17+
// Since we cannot nicely diagnose these problems from the macro itself,
18+
// as it would need to inspect the type and its extensions and all involved
19+
// protocols., as at least
20+
21+
// CHECK: macro expansion @Resolvable:1:[[COL:[0-9]+]]: error: distributed actor '$Fail' does not declare ActorSystem it can be used with
22+
@Resolvable
23+
protocol Fail: DistributedActor {
24+
distributed func method() -> String
25+
}

test/Distributed/Macros/distributed_macro_expansion_DistributedProtocol_various_requirements.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,12 @@ public protocol GreeterMore: DistributedActor where ActorSystem == FakeActorSyst
140140
// CHECK: }
141141
// CHECK: }
142142
// CHECK: }
143+
144+
145+
// Should not fail:
146+
public protocol MyActorWithSystemRequirement: DistributedActor where ActorSystem == FakeActorSystem {}
147+
148+
@Resolvable
149+
public protocol MyActorWithSystemRequirementImpl: MyActorWithSystemRequirement {
150+
distributed func example()
151+
}

0 commit comments

Comments
 (0)