mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Sema: Don't crash if a property with an opaque result type has both an initial value and a getter
This commit is contained in:
@@ -9446,23 +9446,26 @@ applySolutionToInitialization(SyntacticElementTarget target, Expr *initializer,
|
||||
// If this property has an opaque result type, set the underlying type
|
||||
// substitutions based on the initializer.
|
||||
if (auto var = resultTarget.getInitializationPattern()->getSingleVar()) {
|
||||
SubstitutionMap substitutions;
|
||||
if (auto opaque = var->getOpaqueResultTypeDecl()) {
|
||||
resultTarget.getAsExpr()->forEachChildExpr([&](Expr *expr) -> Expr * {
|
||||
if (auto coercionExpr = dyn_cast<UnderlyingToOpaqueExpr>(expr)) {
|
||||
auto newSubstitutions =
|
||||
coercionExpr->substitutions.mapReplacementTypesOutOfContext();
|
||||
if (substitutions.empty()) {
|
||||
substitutions = newSubstitutions;
|
||||
} else {
|
||||
assert(substitutions.getCanonical() ==
|
||||
newSubstitutions.getCanonical());
|
||||
}
|
||||
}
|
||||
return expr;
|
||||
});
|
||||
if (!var->getParsedAccessor(AccessorKind::Get)) {
|
||||
if (auto opaque = var->getOpaqueResultTypeDecl()) {
|
||||
SubstitutionMap substitutions;
|
||||
|
||||
opaque->setUniqueUnderlyingTypeSubstitutions(substitutions);
|
||||
resultTarget.getAsExpr()->forEachChildExpr([&](Expr *expr) -> Expr * {
|
||||
if (auto coercionExpr = dyn_cast<UnderlyingToOpaqueExpr>(expr)) {
|
||||
auto newSubstitutions =
|
||||
coercionExpr->substitutions.mapReplacementTypesOutOfContext();
|
||||
if (substitutions.empty()) {
|
||||
substitutions = newSubstitutions;
|
||||
} else {
|
||||
assert(substitutions.getCanonical() ==
|
||||
newSubstitutions.getCanonical());
|
||||
}
|
||||
}
|
||||
return expr;
|
||||
});
|
||||
|
||||
opaque->setUniqueUnderlyingTypeSubstitutions(substitutions);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user