Skip to content

Commit 5cc9b9b

Browse files
committed
Sema: Don't crash if a property with an opaque result type has both an initial value and a getter
1 parent a4625ba commit 5cc9b9b

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

lib/Sema/CSApply.cpp

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9446,23 +9446,26 @@ applySolutionToInitialization(SyntacticElementTarget target, Expr *initializer,
94469446
// If this property has an opaque result type, set the underlying type
94479447
// substitutions based on the initializer.
94489448
if (auto var = resultTarget.getInitializationPattern()->getSingleVar()) {
9449-
SubstitutionMap substitutions;
9450-
if (auto opaque = var->getOpaqueResultTypeDecl()) {
9451-
resultTarget.getAsExpr()->forEachChildExpr([&](Expr *expr) -> Expr * {
9452-
if (auto coercionExpr = dyn_cast<UnderlyingToOpaqueExpr>(expr)) {
9453-
auto newSubstitutions =
9454-
coercionExpr->substitutions.mapReplacementTypesOutOfContext();
9455-
if (substitutions.empty()) {
9456-
substitutions = newSubstitutions;
9457-
} else {
9458-
assert(substitutions.getCanonical() ==
9459-
newSubstitutions.getCanonical());
9449+
if (!var->getParsedAccessor(AccessorKind::Get)) {
9450+
if (auto opaque = var->getOpaqueResultTypeDecl()) {
9451+
SubstitutionMap substitutions;
9452+
9453+
resultTarget.getAsExpr()->forEachChildExpr([&](Expr *expr) -> Expr * {
9454+
if (auto coercionExpr = dyn_cast<UnderlyingToOpaqueExpr>(expr)) {
9455+
auto newSubstitutions =
9456+
coercionExpr->substitutions.mapReplacementTypesOutOfContext();
9457+
if (substitutions.empty()) {
9458+
substitutions = newSubstitutions;
9459+
} else {
9460+
assert(substitutions.getCanonical() ==
9461+
newSubstitutions.getCanonical());
9462+
}
94609463
}
9461-
}
9462-
return expr;
9463-
});
9464+
return expr;
9465+
});
94649466

9465-
opaque->setUniqueUnderlyingTypeSubstitutions(substitutions);
9467+
opaque->setUniqueUnderlyingTypeSubstitutions(substitutions);
9468+
}
94669469
}
94679470
}
94689471

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// {"kind":"typecheck","original":"3a2652c9","signature":"(anonymous namespace)::OpaqueUnderlyingTypeChecker::check()","signatureAssert":"Assertion failed: (!UniqueUnderlyingType.has_value() && \"resetting underlying type?!\"), function setUniqueUnderlyingTypeSubstitutions"}
2-
// RUN: not --crash %target-swift-frontend -typecheck %s
2+
// RUN: not %target-swift-frontend -typecheck %s
33
var a: some Any = 0.0 {
44
0
55
}

0 commit comments

Comments
 (0)