Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Sources/TestingMacros/Support/AttributeDiscovery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,9 @@ struct AttributeInfo {
let rawIdentifier = namedDecl.name.rawIdentifier {
if let displayName, let displayNameArgument {
context.diagnose(.declaration(namedDecl, hasExtraneousDisplayName: displayName, fromArgument: displayNameArgument, using: attribute))
} else {
displayName = StringLiteralExprSyntax(content: rawIdentifier)
}
displayName = StringLiteralExprSyntax(content: rawIdentifier)
}

// Remove leading "Self." expressions from the arguments of the attribute.
Expand Down
12 changes: 9 additions & 3 deletions Sources/TestingMacros/Support/DiagnosticMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -657,10 +657,16 @@ struct DiagnosticMessage: SwiftDiagnostics.DiagnosticMessage {
fromArgument argumentContainingDisplayName: LabeledExprListSyntax.Element,
using attribute: AttributeSyntax
) -> Self {
Self(
// If the name of the ambiguously-named symbol should be derived from a raw
// identifier, this situation is an error. If the name is not raw but is
// still surrounded by backticks (e.g. "func `foo`()" or "struct `if`") then
// lower the severity to a warning. That way, existing code structured this
// way doesn't suddenly fail to build.
let severity: DiagnosticSeverity = (decl.name.rawIdentifier != nil) ? .error : .warning
return Self(
syntax: Syntax(decl),
message: "Attribute \(_macroName(attribute)) specifies display name '\(displayNameFromAttribute.representedLiteralValue!)' for \(_kindString(for: decl)) with implicit display name '\(decl.name.rawIdentifier!)'",
severity: .error,
message: "Attribute \(_macroName(attribute)) specifies display name '\(displayNameFromAttribute.representedLiteralValue!)' for \(_kindString(for: decl)) with implicit display name '\(decl.name.textWithoutBackticks)'",
severity: severity,
fixIts: [
FixIt(
message: MacroExpansionFixItMessage("Remove '\(displayNameFromAttribute.representedLiteralValue!)'"),
Expand Down