@@ -321,65 +321,57 @@ struct DiagnosticMessage: SwiftDiagnostics.DiagnosticMessage {
321
321
/// generic.
322
322
/// - attribute: The `@Test` or `@Suite` attribute.
323
323
/// - decl: The declaration in question (contained in `node`.)
324
+ /// - escapableNonConformance: The suppressed conformance to `Escapable` for
325
+ /// `decl`, if present.
324
326
///
325
327
/// - Returns: A diagnostic message.
326
- static func containingNodeUnsupported( _ node: some SyntaxProtocol , genericBecauseOf genericClause: Syntax ? = nil , whenUsing attribute: AttributeSyntax , on decl: some SyntaxProtocol ) -> Self {
328
+ static func containingNodeUnsupported( _ node: some SyntaxProtocol , genericBecauseOf genericClause: Syntax ? = nil , whenUsing attribute: AttributeSyntax , on decl: some SyntaxProtocol , withSuppressedConformanceToEscapable escapableNonConformance : SuppressedTypeSyntax ? = nil ) -> Self {
327
329
// Avoid using a syntax node from a lexical context (it won't have source
328
330
// location information.)
329
331
let syntax : Syntax = if let genericClause, attribute. root == genericClause. root {
330
332
// Prefer the generic clause if available as the root cause.
331
333
genericClause
334
+ } else if let escapableNonConformance, attribute. root == escapableNonConformance. root {
335
+ // Then the ~Escapable conformance if present.
336
+ Syntax ( escapableNonConformance)
332
337
} else if attribute. root == node. root {
333
- // Second choice is the unsupported containing node.
338
+ // Next best choice is the unsupported containing node.
334
339
Syntax ( node)
335
340
} else {
336
341
// Finally, fall back to the attribute, which we assume is not detached.
337
342
Syntax ( attribute)
338
343
}
344
+
345
+ // Figure out the message to present.
346
+ var message = " Attribute \( _macroName ( attribute) ) cannot be applied to \( _kindString ( for: decl, includeA: true ) ) "
339
347
let generic = if genericClause != nil {
340
348
" generic "
341
349
} else {
342
350
" "
343
351
}
344
352
if let functionDecl = node. as ( FunctionDeclSyntax . self) {
345
- let functionName = functionDecl. completeName
346
- return Self (
347
- syntax: syntax,
348
- message: " Attribute \( _macroName ( attribute) ) cannot be applied to \( _kindString ( for: decl, includeA: true ) ) within \( generic) function ' \( functionName) ' " ,
349
- severity: . error
350
- )
353
+ message += " within \( generic) function ' \( functionDecl. completeName) ' "
351
354
} else if let namedDecl = node. asProtocol ( ( any NamedDeclSyntax ) . self) {
352
- let declName = namedDecl. name. textWithoutBackticks
353
- return Self (
354
- syntax: syntax,
355
- message: " Attribute \( _macroName ( attribute) ) cannot be applied to \( _kindString ( for: decl, includeA: true ) ) within \( generic) \( _kindString ( for: node) ) ' \( declName) ' " ,
356
- severity: . error
357
- )
355
+ message += " within \( generic) \( _kindString ( for: node) ) ' \( namedDecl. name. textWithoutBackticks) ' "
358
356
} else if let extensionDecl = node. as ( ExtensionDeclSyntax . self) {
359
357
// Subtly different phrasing from the NamedDeclSyntax case above.
360
- let nodeKind = if genericClause != nil {
361
- " a generic extension to type "
358
+ if genericClause != nil {
359
+ message += " within a generic extension to type ' \( extensionDecl . extendedType . trimmedDescription ) ' "
362
360
} else {
363
- " an extension to type "
361
+ message += " within an extension to type ' \( extensionDecl . extendedType . trimmedDescription ) ' "
364
362
}
365
- let declGroupName = extensionDecl. extendedType. trimmedDescription
366
- return Self (
367
- syntax: syntax,
368
- message: " Attribute \( _macroName ( attribute) ) cannot be applied to \( _kindString ( for: decl, includeA: true ) ) within \( nodeKind) ' \( declGroupName) ' " ,
369
- severity: . error
370
- )
371
363
} else {
372
- let nodeKind = if genericClause != nil {
373
- " a generic \( _kindString ( for: node) ) "
364
+ if genericClause != nil {
365
+ message += " within a generic \( _kindString ( for: node) ) "
374
366
} else {
375
- _kindString ( for: node, includeA: true )
367
+ message += " within \( _kindString ( for: node, includeA: true ) ) "
376
368
}
377
- return Self (
378
- syntax: syntax,
379
- message: " Attribute \( _macroName ( attribute) ) cannot be applied to \( _kindString ( for: decl, includeA: true ) ) within \( nodeKind) " ,
380
- severity: . error
381
- )
382
369
}
370
+ if escapableNonConformance != nil {
371
+ message += " because its conformance to 'Escapable' has been suppressed "
372
+ }
373
+
374
+ return Self ( syntax: syntax, message: message, severity: . error)
383
375
}
384
376
385
377
/// Create a diagnostic message stating that the given attribute cannot be
0 commit comments