mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Distributed] add note explaining DefaultDistributedActorSystem
This commit is contained in:
@@ -4496,11 +4496,12 @@ ERROR(actor_protocol_illegal_inheritance,none,
|
||||
"non-actor type %0 cannot conform to the 'Actor' protocol",
|
||||
(DeclName))
|
||||
ERROR(distributed_actor_conformance_missing_system_type,none,
|
||||
"distributed actor %0 does not declare ActorSystem it can be used with. "
|
||||
"Declare the associated actor system with a 'typealias ActorSystem = MyActorSystem' "
|
||||
"inside the actor, or module-wide by declaring a global 'typealias "
|
||||
"DefaultDistributedActorSystem = MyActorSystem'.",
|
||||
"distributed actor %0 does not declare ActorSystem it can be used with.",
|
||||
(DeclName))
|
||||
NOTE(note_distributed_actor_system_can_be_defined_using_defaultdistributedactorsystem,none,
|
||||
"you can provide a module-wide default actor system by declaring:\n"
|
||||
"typealias DefaultDistributedActorSystem = <#ConcreteActorSystem#>\n",
|
||||
())
|
||||
ERROR(distributed_actor_protocol_illegal_inheritance,none,
|
||||
"non-distributed actor type %0 cannot conform to the 'DistributedActor' protocol",
|
||||
(DeclName))
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "swift/AST/AccessScope.h"
|
||||
#include "swift/AST/ClangModuleLoader.h"
|
||||
#include "swift/AST/Decl.h"
|
||||
#include "swift/AST/DistributedDecl.h"
|
||||
#include "swift/AST/Effects.h"
|
||||
#include "swift/AST/ExistentialLayout.h"
|
||||
#include "swift/AST/GenericEnvironment.h"
|
||||
@@ -5486,17 +5487,13 @@ void swift::diagnoseConformanceFailure(Type T,
|
||||
return;
|
||||
|
||||
// If it is missing the ActorSystem type, suggest adding it:
|
||||
// FIXME(distributed): use getDistributedActorSystemType(nominal); once merged
|
||||
auto &C = nominal->getASTContext();
|
||||
auto DA = C.getDistributedActorDecl();
|
||||
Type selfType = nominal->getSelfInterfaceType();
|
||||
auto conformance = nominal->getParentModule()->lookupConformance(selfType, DA);
|
||||
auto systemTy = conformance.getTypeWitnessByName(selfType, C.Id_ActorSystem);
|
||||
|
||||
auto systemTy = getDistributedActorSystemType(/*actor=*/nominal);
|
||||
if (!systemTy || systemTy->hasError()) {
|
||||
diags.diagnose(ComplainLoc,
|
||||
diag::distributed_actor_conformance_missing_system_type,
|
||||
nominal->getName());
|
||||
diags.diagnose(nominal->getStartLoc(),
|
||||
diag::note_distributed_actor_system_can_be_defined_using_defaultdistributedactorsystem);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
16
test/Distributed/distributed_actor_system_missing.swift
Normal file
16
test/Distributed/distributed_actor_system_missing.swift
Normal file
@@ -0,0 +1,16 @@
|
||||
// RUN: %target-swift-frontend -typecheck -verify -enable-experimental-distributed -disable-availability-checking -I %t 2>&1 %s
|
||||
|
||||
// UNSUPPORTED: back_deploy_concurrency
|
||||
// REQUIRES: concurrency
|
||||
// REQUIRES: distributed
|
||||
|
||||
import _Distributed
|
||||
|
||||
distributed actor DA {
|
||||
// expected-error@-1{{distributed actor 'DA' does not declare ActorSystem it can be used with.}}
|
||||
|
||||
// expected-note@-3{{you can provide a module-wide default actor system by declaring:}}
|
||||
|
||||
// Note to add the typealias is diagnosed on the protocol:
|
||||
// _Distributed.DistributedActor:3:20: note: diagnostic produced elsewhere: protocol requires nested type 'ActorSystem'; do you want to add it?
|
||||
}
|
||||
Reference in New Issue
Block a user