diff --git a/lib/AST/LifetimeDependence.cpp b/lib/AST/LifetimeDependence.cpp index 59f0531fe3d54..a4014eca99545 100644 --- a/lib/AST/LifetimeDependence.cpp +++ b/lib/AST/LifetimeDependence.cpp @@ -962,7 +962,7 @@ class LifetimeDependenceChecker { diagnose(returnLoc, diag::lifetime_dependence_cannot_infer_scope_ownership, param->getParameterName().str(), diagnosticQualifier()); - continue; + return; } targetDeps = std::move(targetDeps).add(paramIndex, *kind); } diff --git a/test/Sema/lifetime_depend_infer.swift b/test/Sema/lifetime_depend_infer.swift index ede6a1a2ca0a9..10876e5cf023c 100644 --- a/test/Sema/lifetime_depend_infer.swift +++ b/test/Sema/lifetime_depend_infer.swift @@ -168,6 +168,12 @@ struct EscapableNonTrivialSelf { // (for initializers and stand-alone functions) // ============================================================================= +// An implicit initializer illegally consumes its nontrivial parameter. +public struct NonescapableImplicitInitializer: ~Escapable { + // expected-error @-1{{cannot borrow the lifetime of 'c', which has consuming ownership on an implicit initializer}} + var c: C +} + struct NonescapableInitializers: ~Escapable { var c: C