Skip to content

Commit baa02e0

Browse files
committed
LifetimeDependence: fix a type checker crash on implicit init
When the type checker diagnoses an error on an implicit initializer, return immediately before handling its parameter to avoid an assert. (cherry picked from commit e9ac803)
1 parent 716b660 commit baa02e0

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/AST/LifetimeDependence.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,7 @@ class LifetimeDependenceChecker {
962962
diagnose(returnLoc,
963963
diag::lifetime_dependence_cannot_infer_scope_ownership,
964964
param->getParameterName().str(), diagnosticQualifier());
965-
continue;
965+
return;
966966
}
967967
targetDeps = std::move(targetDeps).add(paramIndex, *kind);
968968
}

test/Sema/lifetime_depend_infer.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,12 @@ struct EscapableNonTrivialSelf {
168168
// (for initializers and stand-alone functions)
169169
// =============================================================================
170170

171+
// An implicit initializer illegally consumes its nontrivial parameter.
172+
public struct NonescapableImplicitInitializer: ~Escapable {
173+
// expected-error @-1{{cannot borrow the lifetime of 'c', which has consuming ownership on an implicit initializer}}
174+
var c: C
175+
}
176+
171177
struct NonescapableInitializers: ~Escapable {
172178
var c: C
173179

0 commit comments

Comments
 (0)