AST: Source range of FuncDecl/ConstructorDecl should include the thrown type

When a function declaration has a body, its source range ends at the
closing curly brace, so it includes the `throws(E)`. However, a
protocol requirement doesn't have a body, and due to an oversight,
getSourceRange() was never updated to include the extra tokens
that appear after `throws` when the function declares a thrown
error type. As a result, unqualified lookup would fail to find a
generic parameter type, if that happened to be the thrown type.

Fixes rdar://problem/143950572.
This commit is contained in:
Slava Pestov
2025-02-07 13:55:12 -05:00
parent 4937d0a242
commit a6a96da558
6 changed files with 70 additions and 44 deletions

View File

@@ -890,17 +890,17 @@ static void setLocationInfo(const ValueDecl *VD,
auto Loc = VD->getLoc(/*SerializedOK=*/true);
if (Loc.isValid()) {
auto getSignatureRange =
auto getParameterListRange =
[&](const ValueDecl *VD) -> std::optional<unsigned> {
if (auto FD = dyn_cast<AbstractFunctionDecl>(VD)) {
SourceRange R = FD->getSignatureSourceRange();
SourceRange R = FD->getParameterListSourceRange();
if (R.isValid())
return getCharLength(SM, R);
}
return std::nullopt;
};
unsigned NameLen;
if (auto SigLen = getSignatureRange(VD)) {
if (auto SigLen = getParameterListRange(VD)) {
NameLen = SigLen.value();
} else if (VD->hasName()) {
NameLen = VD->getBaseName().userFacingName().size();