mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
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:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user