mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Type checker] Fail more usefully if something synthesizes a bogus attribute.
No part of the compiler, including the Clang importer, should synthesize an attribute that would fail early attribute validation. When it happens, it would emit diagnostics with no location information, which is really annoyingly hard to debug. Instead, assert that this doesn't happen, i.e., both that the Clang importer doesn't synthesize bogus attributes (as in the previous commit) and that nothing synthesizes such attributes with empty source location informations. In non-asserting builds, just suppress the diagnostic.
This commit is contained in:
@@ -42,8 +42,19 @@ public:
|
||||
/// This emits a diagnostic with a fixit to remove the attribute.
|
||||
template<typename ...ArgTypes>
|
||||
void diagnoseAndRemoveAttr(DeclAttribute *attr, ArgTypes &&...Args) {
|
||||
TC.diagnose(attr->getLocation(), std::forward<ArgTypes>(Args)...)
|
||||
.fixItRemove(attr->getRangeWithAt());
|
||||
assert(!D->hasClangNode() && "Clang imported propagated a bogus attribute");
|
||||
if (!D->hasClangNode()) {
|
||||
SourceLoc loc = attr->getLocation();
|
||||
assert(loc.isValid() && "Diagnosing attribute with invalid location");
|
||||
if (loc.isInvalid()) {
|
||||
loc = D->getLoc();
|
||||
}
|
||||
if (loc.isValid()) {
|
||||
TC.diagnose(loc, std::forward<ArgTypes>(Args)...)
|
||||
.fixItRemove(attr->getRangeWithAt());
|
||||
}
|
||||
}
|
||||
|
||||
attr->setInvalid();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user