Skip to content

Lower the "ambiguous display name" diagnostic to a warning for some names. #1175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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