@@ -218,19 +218,26 @@ getLifetimeDependenceKind(LifetimeEntry specifier, AbstractFunctionDecl *afd,
218218 auto ownership = decl->getValueOwnership ();
219219 auto type = decl->getTypeInContext ();
220220
221- // For @lifetime attribute, we determine lifetime dependence kind based on
222- // type .
221+ // For @lifetime attribute, we check if we had a "borrow" modifier, if not
222+ // we infer inherit dependence .
223223 if (afd->getAttrs ().hasAttribute <LifetimeAttr>()) {
224- auto lifetimeKind = getLifetimeDependenceKindFromType (type);
225- bool isCompatible = isLifetimeDependenceCompatibleWithOwnership (
226- lifetimeKind, type, ownership, afd);
227- if (!isCompatible) {
228- assert (lifetimeKind == LifetimeDependenceKind::Scope);
229- diags.diagnose (
230- loc, diag::lifetime_dependence_cannot_use_inferred_scoped_consuming);
224+ auto parsedLifetimeKind = specifier.getParsedLifetimeDependenceKind ();
225+ if (parsedLifetimeKind == ParsedLifetimeDependenceKind::Scope) {
226+ bool isCompatible = isLifetimeDependenceCompatibleWithOwnership (
227+ LifetimeDependenceKind::Scope, type, ownership, afd);
228+ if (!isCompatible) {
229+ diags.diagnose (
230+ loc, diag::lifetime_dependence_cannot_use_parsed_borrow_consuming);
231+ return std::nullopt ;
232+ }
233+ return LifetimeDependenceKind::Scope;
234+ }
235+ if (type->isEscapable ()) {
236+ diags.diagnose (loc,
237+ diag::lifetime_dependence_invalid_inherit_escapable_type);
231238 return std::nullopt ;
232239 }
233- return lifetimeKind ;
240+ return LifetimeDependenceKind::Inherit ;
234241 }
235242
236243 // For dependsOn type modifier, we check if we had a "scoped" modifier, if not
0 commit comments