Lifetimes: add a diagnostic note for implicit accessors

Lifetime diagnostics may report an error within an implicit initializer or
accessor. The source location is misleading in these cases and causes much
consternation.
This commit is contained in:
Andrew Trick
2025-09-13 18:00:57 -07:00
parent 9953b1e3db
commit 771e9b522e
5 changed files with 50 additions and 0 deletions

View File

@@ -1240,6 +1240,8 @@ NOTE(lifetime_outside_scope_use, none,
NOTE(lifetime_outside_scope_escape, none,
"this use causes the lifetime-dependent value to escape", ())
NOTE(implicit_function_note, none, "error in compiler-generated '%0'", (StringRef))
ERROR(noncopyable_shared_case_block_unimplemented, none,
"matching a non-'Copyable' value using a case label that has multiple patterns is not implemented", ())

View File

@@ -509,6 +509,9 @@ struct BridgedFunction {
BridgedOwnedString getDebugDescription() const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedLocation getLocation() const;
BRIDGED_INLINE bool isAccessor() const;
BRIDGED_INLINE bool isInitializer() const;
BRIDGED_INLINE bool isDeinitializer() const;
BRIDGED_INLINE bool isImplicit() const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedStringRef getAccessorName() const;
BRIDGED_INLINE bool hasOwnership() const;
BRIDGED_INLINE bool hasLoweredAddresses() const;

View File

@@ -701,6 +701,21 @@ BridgedStringRef BridgedFunction::getAccessorName() const {
return accessorKindName(accessorDecl->getAccessorKind());
}
bool BridgedFunction::isInitializer() const {
return getFunction()->getDeclRef().isConstructor();
}
bool BridgedFunction::isDeinitializer() const {
return getFunction()->getDeclRef().isDestructor();
}
bool BridgedFunction::isImplicit() const {
if (auto *funcDecl = getFunction()->getDeclRef().getAbstractFunctionDecl()) {
return funcDecl->isImplicit();
}
return false;
}
bool BridgedFunction::hasOwnership() const { return getFunction()->hasOwnership(); }
bool BridgedFunction::hasLoweredAddresses() const { return getFunction()->getModule().useLoweredAddresses(); }