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.
|
// Try resolving an attached macro attribute.
|
||||||
if (auto *macro = D->getResolvedMacro(attr)) {
|
if (auto *macro = D->getResolvedMacro(attr)) {
|
||||||
for (auto *roleAttr : macro->getAttrs().getAttributes<MacroRoleAttr>()) {
|
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;
|
return;
|
||||||
|
|||||||
@@ -543,7 +543,7 @@ static Identifier makeIdentifier(ASTContext &ctx, std::nullptr_t) {
|
|||||||
return Identifier();
|
return Identifier();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool swift::diagnoseInvalidAttachedMacro(MacroRole role,
|
bool swift::isInvalidAttachedMacro(MacroRole role,
|
||||||
Decl *attachedTo) {
|
Decl *attachedTo) {
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case MacroRole::Expression:
|
case MacroRole::Expression:
|
||||||
@@ -582,9 +582,6 @@ bool swift::diagnoseInvalidAttachedMacro(MacroRole role,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
attachedTo->diagnose(diag::macro_attached_to_invalid_decl,
|
|
||||||
getMacroRoleString(role),
|
|
||||||
attachedTo->getDescriptiveKind());
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -90,9 +90,9 @@ bool accessorMacroOnlyIntroducesObservers(
|
|||||||
bool accessorMacroIntroducesInitAccessor(
|
bool accessorMacroIntroducesInitAccessor(
|
||||||
MacroDecl *macro, const MacroRoleAttr *attr);
|
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.
|
/// to the declaration kind of \c attachedTo.
|
||||||
bool diagnoseInvalidAttachedMacro(MacroRole role,
|
bool isInvalidAttachedMacro(MacroRole role,
|
||||||
Decl *attachedTo);
|
Decl *attachedTo);
|
||||||
|
|
||||||
} // end namespace swift
|
} // end namespace swift
|
||||||
|
|||||||
@@ -144,9 +144,9 @@ expansionOrder.originalMember = 28
|
|||||||
#if TEST_DIAGNOSTICS
|
#if TEST_DIAGNOSTICS
|
||||||
@wrapAllProperties
|
@wrapAllProperties
|
||||||
typealias A = Int
|
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
|
@wrapAllProperties
|
||||||
func noMembers() {}
|
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
|
#endif
|
||||||
|
|||||||
@@ -113,11 +113,11 @@ func testLocal() {
|
|||||||
|
|
||||||
@DelegatedConformance
|
@DelegatedConformance
|
||||||
typealias A = Int
|
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
|
@DelegatedConformance
|
||||||
extension Int {}
|
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)
|
@attached(extension, conformances: P)
|
||||||
macro UndocumentedNamesInExtension() = #externalMacro(module: "MacroDefinition", type: "DelegatedConformanceViaExtensionMacro")
|
macro UndocumentedNamesInExtension() = #externalMacro(module: "MacroDefinition", type: "DelegatedConformanceViaExtensionMacro")
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ macro addMembersQuotedInit() = #externalMacro(module: "MacroDefinition", type: "
|
|||||||
#if TEST_DIAGNOSTICS
|
#if TEST_DIAGNOSTICS
|
||||||
@addMembers
|
@addMembers
|
||||||
import Swift
|
import Swift
|
||||||
// expected-error@-1 {{'member' macro cannot be attached to import}}
|
// expected-error@-2 {{'member' macro cannot be attached to import}}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@addMembers
|
@addMembers
|
||||||
|
|||||||
Reference in New Issue
Block a user