Skip to content

Commit 78ea361

Browse files
committed
[AST] Override getLocFromSource for ParamDecl
Ensure we can still produce a source location even if there's no name loc, which is the case for e.g enum associated types.
1 parent 9f5a754 commit 78ea361

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

include/swift/AST/Decl.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7101,6 +7101,14 @@ class ParamDecl : public VarDecl {
71017101
Identifier parameterName, Expr *defaultValue,
71027102
DefaultArgumentInitializer *defaultValueInitContext, DeclContext *dc);
71037103

7104+
SourceLoc getLocFromSource() const {
7105+
// If we have a name loc, use it, otherwise fallback to the start loc for
7106+
// e.g enum elements without parameter names.
7107+
if (auto nameLoc = getNameLoc())
7108+
return nameLoc;
7109+
return getStartLoc();
7110+
}
7111+
71047112
/// Retrieve the argument (API) name for this function parameter.
71057113
Identifier getArgumentName() const {
71067114
return ArgumentNameAndFlags.getPointer();
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// {"kind":"typecheck","signature":"printDifferentiableAttrArguments(swift::DifferentiableAttr const*, swift::ASTPrinter&, swift::PrintOptions const&, swift::Decl const*, bool)","signatureAssert":"Assertion failed: (original && \"Must resolve original declaration\"), function printDifferentiableAttrArguments"}
2-
// RUN: not --crash %target-swift-frontend -typecheck %s
2+
// RUN: not %target-swift-frontend -typecheck %s
33
func a(@differentiable _ =

0 commit comments

Comments
 (0)