@@ -321,65 +321,57 @@ struct DiagnosticMessage: SwiftDiagnostics.DiagnosticMessage {
321321 /// generic.
322322 /// - attribute: The `@Test` or `@Suite` attribute.
323323 /// - decl: The declaration in question (contained in `node`.)
324+ /// - escapableNonConformance: The suppressed conformance to `Escapable` for
325+ /// `decl`, if present.
324326 ///
325327 /// - 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 {
327329 // Avoid using a syntax node from a lexical context (it won't have source
328330 // location information.)
329331 let syntax : Syntax = if let genericClause, attribute. root == genericClause. root {
330332 // Prefer the generic clause if available as the root cause.
331333 genericClause
334+ } else if let escapableNonConformance, attribute. root == escapableNonConformance. root {
335+ // Then the ~Escapable conformance if present.
336+ Syntax ( escapableNonConformance)
332337 } else if attribute. root == node. root {
333- // Second choice is the unsupported containing node.
338+ // Next best choice is the unsupported containing node.
334339 Syntax ( node)
335340 } else {
336341 // Finally, fall back to the attribute, which we assume is not detached.
337342 Syntax ( attribute)
338343 }
344+
345+ // Figure out the message to present.
346+ var message = " Attribute \( _macroName ( attribute) ) cannot be applied to \( _kindString ( for: decl, includeA: true ) ) "
339347 let generic = if genericClause != nil {
340348 " generic "
341349 } else {
342350 " "
343351 }
344352 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) ' "
351354 } 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) ' "
358356 } else if let extensionDecl = node. as ( ExtensionDeclSyntax . self) {
359357 // 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 ) ' "
362360 } else {
363- " an extension to type "
361+ message += " within an extension to type ' \( extensionDecl . extendedType . trimmedDescription ) ' "
364362 }
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- )
371363 } 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) ) "
374366 } else {
375- _kindString ( for: node, includeA: true )
367+ message += " within \( _kindString ( for: node, includeA: true ) ) "
376368 }
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- )
382369 }
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)
383375 }
384376
385377 /// Create a diagnostic message stating that the given attribute cannot be
0 commit comments