2121#include " swift/AST/Decl.h"
2222#include " swift/AST/DiagnosticsSema.h"
2323#include " swift/AST/Expr.h"
24+ #include " swift/AST/Module.h"
2425#include " swift/AST/ParameterList.h"
2526#include " swift/AST/TypeRepr.h"
2627#include " swift/Basic/Assertions.h"
@@ -55,6 +56,27 @@ class NonisolatedNonsendingByDefaultMigrationTarget {
5556 // / behavior.
5657 void diagnose () const ;
5758};
59+
60+ // / Determine whether the decl represents a test function that is
61+ // / annotated with `@Test` macro from the swift-testing framework.
62+ // / Such functions should be exempt from the migration because their
63+ // / execution is controlled by the framework and the change in
64+ // / behavior doesn't affect them.
65+ static bool isSwiftTestingTestFunction (ValueDecl *decl) {
66+ if (!isa<FuncDecl>(decl))
67+ return false ;
68+
69+ return llvm::any_of (decl->getAttrs (), [&decl](DeclAttribute *attr) {
70+ auto customAttr = dyn_cast<CustomAttr>(attr);
71+ if (!customAttr)
72+ return false ;
73+
74+ auto *macro = decl->getResolvedMacro (customAttr);
75+ return macro && macro->getBaseIdentifier ().is (" Test" ) &&
76+ macro->getParentModule ()->getName ().is (" Testing" );
77+ });
78+ }
79+
5880} // end anonymous namespace
5981
6082void NonisolatedNonsendingByDefaultMigrationTarget::diagnose () const {
@@ -78,6 +100,17 @@ void NonisolatedNonsendingByDefaultMigrationTarget::diagnose() const {
78100 return ;
79101 }
80102
103+ // `@Test` test-case have special semantics.
104+ if (isSwiftTestingTestFunction (decl)) {
105+ return ;
106+ }
107+
108+ // A special declaration that was either synthesized by the compiler
109+ // or a macro expansion.
110+ if (decl->getBaseName ().hasDollarPrefix ()) {
111+ return ;
112+ }
113+
81114 // If the attribute cannot appear on this kind of declaration, we can't
82115 // diagnose it.
83116 if (!DeclAttribute::canAttributeAppearOnDecl (DeclAttrKind::Concurrent,
0 commit comments