Skip to content

Commit acbc913

Browse files
committed
[AST] Add convenient AccessorDecl::isImplicitGetter()
1 parent 8936633 commit acbc913

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

include/swift/AST/Decl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6417,6 +6417,10 @@ class AccessorDecl final : public FuncDecl {
64176417
llvm_unreachable("bad accessor kind");
64186418
}
64196419

6420+
bool isImplicitGetter() const {
6421+
return isGetter() && getAccessorKeywordLoc().isInvalid();
6422+
}
6423+
64206424
void setIsTransparent(bool transparent) {
64216425
Bits.AccessorDecl.IsTransparent = transparent;
64226426
Bits.AccessorDecl.IsTransparentComputed = 1;

lib/AST/Decl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ SourceRange Decl::getSourceRangeIncludingAttrs() const {
520520
// e.g. 'override'.
521521
if (auto *AD = dyn_cast<AccessorDecl>(this)) {
522522
// If this is implicit getter, accessor range should not include attributes.
523-
if (!AD->getAccessorKeywordLoc().isValid())
523+
if (AD->isImplicitGetter())
524524
return Range;
525525

526526
// Otherwise, include attributes directly attached to the accessor.
@@ -5937,7 +5937,7 @@ void VarDecl::emitLetToVarNoteIfSimple(DeclContext *UseDC) const {
59375937
->hasReferenceSemantics()) {
59385938
// Do not suggest the fix-it in implicit getters
59395939
if (auto AD = dyn_cast<AccessorDecl>(FD)) {
5940-
if (AD->isGetter() && !AD->getAccessorKeywordLoc().isValid())
5940+
if (AD->isImplicitGetter())
59415941
return;
59425942
}
59435943

0 commit comments

Comments
 (0)