mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Merge pull request #67461 from hborla/invalid-attached-macro-loc
This commit is contained in:
@@ -3686,7 +3686,13 @@ void AttributeChecker::visitCustomAttr(CustomAttr *attr) {
|
||||
// Try resolving an attached macro attribute.
|
||||
if (auto *macro = D->getResolvedMacro(attr)) {
|
||||
for (auto *roleAttr : macro->getAttrs().getAttributes<MacroRoleAttr>()) {
|
||||
diagnoseInvalidAttachedMacro(roleAttr->getMacroRole(), D);
|
||||
auto role = roleAttr->getMacroRole();
|
||||
if (isInvalidAttachedMacro(role, D)) {
|
||||
diagnoseAndRemoveAttr(attr,
|
||||
diag::macro_attached_to_invalid_decl,
|
||||
getMacroRoleString(role),
|
||||
D->getDescriptiveKind());
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
@@ -543,8 +543,8 @@ static Identifier makeIdentifier(ASTContext &ctx, std::nullptr_t) {
|
||||
return Identifier();
|
||||
}
|
||||
|
||||
bool swift::diagnoseInvalidAttachedMacro(MacroRole role,
|
||||
Decl *attachedTo) {
|
||||
bool swift::isInvalidAttachedMacro(MacroRole role,
|
||||
Decl *attachedTo) {
|
||||
switch (role) {
|
||||
case MacroRole::Expression:
|
||||
case MacroRole::Declaration:
|
||||
@@ -582,9 +582,6 @@ bool swift::diagnoseInvalidAttachedMacro(MacroRole role,
|
||||
break;
|
||||
}
|
||||
|
||||
attachedTo->diagnose(diag::macro_attached_to_invalid_decl,
|
||||
getMacroRoleString(role),
|
||||
attachedTo->getDescriptiveKind());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -90,10 +90,10 @@ bool accessorMacroOnlyIntroducesObservers(
|
||||
bool accessorMacroIntroducesInitAccessor(
|
||||
MacroDecl *macro, const MacroRoleAttr *attr);
|
||||
|
||||
/// Diagnose an error if the given macro role does not apply
|
||||
/// Return true if the given macro role does not apply
|
||||
/// to the declaration kind of \c attachedTo.
|
||||
bool diagnoseInvalidAttachedMacro(MacroRole role,
|
||||
Decl *attachedTo);
|
||||
bool isInvalidAttachedMacro(MacroRole role,
|
||||
Decl *attachedTo);
|
||||
|
||||
} // end namespace swift
|
||||
|
||||
|
||||
@@ -144,9 +144,9 @@ expansionOrder.originalMember = 28
|
||||
#if TEST_DIAGNOSTICS
|
||||
@wrapAllProperties
|
||||
typealias A = Int
|
||||
// expected-error@-1{{'memberAttribute' macro cannot be attached to type alias}}
|
||||
// expected-error@-2{{'memberAttribute' macro cannot be attached to type alias}}
|
||||
|
||||
@wrapAllProperties
|
||||
func noMembers() {}
|
||||
// expected-error@-1{{'memberAttribute' macro cannot be attached to global function}}
|
||||
// expected-error@-2{{'memberAttribute' macro cannot be attached to global function}}
|
||||
#endif
|
||||
|
||||
@@ -113,11 +113,11 @@ func testLocal() {
|
||||
|
||||
@DelegatedConformance
|
||||
typealias A = Int
|
||||
// expected-error@-1 {{'extension' macro cannot be attached to type alias}}
|
||||
// expected-error@-2 {{'extension' macro cannot be attached to type alias}}
|
||||
|
||||
@DelegatedConformance
|
||||
extension Int {}
|
||||
// expected-error@-1 {{'extension' macro cannot be attached to extension}}
|
||||
// expected-error@-2 {{'extension' macro cannot be attached to extension}}
|
||||
|
||||
@attached(extension, conformances: P)
|
||||
macro UndocumentedNamesInExtension() = #externalMacro(module: "MacroDefinition", type: "DelegatedConformanceViaExtensionMacro")
|
||||
|
||||
@@ -22,7 +22,7 @@ macro addMembersQuotedInit() = #externalMacro(module: "MacroDefinition", type: "
|
||||
#if TEST_DIAGNOSTICS
|
||||
@addMembers
|
||||
import Swift
|
||||
// expected-error@-1 {{'member' macro cannot be attached to import}}
|
||||
// expected-error@-2 {{'member' macro cannot be attached to import}}
|
||||
#endif
|
||||
|
||||
@addMembers
|
||||
|
||||
Reference in New Issue
Block a user