Skip to content

Commit d3a8a9a

Browse files
authored
Merge pull request #84628 from slavapestov/tiny-fuzzer-fixes
Two minor fixes for issues discovered by the fuzzer
2 parents 7122a11 + 5cc9b9b commit d3a8a9a

File tree

5 files changed

+24
-18
lines changed

5 files changed

+24
-18
lines changed

lib/Sema/CSApply.cpp

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9456,23 +9456,26 @@ applySolutionToInitialization(SyntacticElementTarget target, Expr *initializer,
94569456
// If this property has an opaque result type, set the underlying type
94579457
// substitutions based on the initializer.
94589458
if (auto var = resultTarget.getInitializationPattern()->getSingleVar()) {
9459-
SubstitutionMap substitutions;
9460-
if (auto opaque = var->getOpaqueResultTypeDecl()) {
9461-
resultTarget.getAsExpr()->forEachChildExpr([&](Expr *expr) -> Expr * {
9462-
if (auto coercionExpr = dyn_cast<UnderlyingToOpaqueExpr>(expr)) {
9463-
auto newSubstitutions =
9464-
coercionExpr->substitutions.mapReplacementTypesOutOfContext();
9465-
if (substitutions.empty()) {
9466-
substitutions = newSubstitutions;
9467-
} else {
9468-
assert(substitutions.getCanonical() ==
9469-
newSubstitutions.getCanonical());
9459+
if (!var->getParsedAccessor(AccessorKind::Get)) {
9460+
if (auto opaque = var->getOpaqueResultTypeDecl()) {
9461+
SubstitutionMap substitutions;
9462+
9463+
resultTarget.getAsExpr()->forEachChildExpr([&](Expr *expr) -> Expr * {
9464+
if (auto coercionExpr = dyn_cast<UnderlyingToOpaqueExpr>(expr)) {
9465+
auto newSubstitutions =
9466+
coercionExpr->substitutions.mapReplacementTypesOutOfContext();
9467+
if (substitutions.empty()) {
9468+
substitutions = newSubstitutions;
9469+
} else {
9470+
assert(substitutions.getCanonical() ==
9471+
newSubstitutions.getCanonical());
9472+
}
94709473
}
9471-
}
9472-
return expr;
9473-
});
9474+
return expr;
9475+
});
94749476

9475-
opaque->setUniqueUnderlyingTypeSubstitutions(substitutions);
9477+
opaque->setUniqueUnderlyingTypeSubstitutions(substitutions);
9478+
}
94769479
}
94779480
}
94789481

lib/Sema/TypeOfReference.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1758,6 +1758,9 @@ static bool isExistentialMemberAccessWithExplicitBaseExpression(
17581758
Type ConstraintSystem::getMemberReferenceTypeFromOpenedType(
17591759
Type type, Type baseObjTy, ValueDecl *value,
17601760
ConstraintLocator *locator, bool hasAppliedSelf, bool isDynamicLookup) {
1761+
if (isa<MacroDecl>(value) || type->is<ErrorType>())
1762+
return ErrorType::get(getASTContext());
1763+
17611764
auto *outerDC = value->getDeclContext();
17621765

17631766
// Cope with dynamic 'Self'.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// {"kind":"complete","original":"098f0ede","signature":"swift::constraints::ConstraintSystem::getMemberReferenceTypeFromOpenedType(swift::Type, swift::Type, swift::ValueDecl*, swift::constraints::ConstraintLocator*, bool, bool)","signatureAssert":"Assertion failed: (isa<To>(Val) && \"cast<Ty>() argument of incompatible type!\"), function cast"}
2-
// RUN: not --crash %target-swift-ide-test -code-completion -batch-code-completion -skip-filecheck -code-completion-diagnostics -source-filename %s
2+
// RUN: %target-swift-ide-test -code-completion -batch-code-completion -skip-filecheck -code-completion-diagnostics -source-filename %s
33
enum a<b> {
44
c=d#^^# macro d()
55
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// {"kind":"typecheck","original":"098f0ede","signature":"swift::constraints::ConstraintSystem::getMemberReferenceTypeFromOpenedType(swift::Type, swift::Type, swift::ValueDecl*, swift::constraints::ConstraintLocator*, bool, bool)","signatureAssert":"Assertion failed: (isa<To>(Val) && \"cast<Ty>() argument of incompatible type!\"), function cast"}
2-
// RUN: not --crash %target-swift-frontend -typecheck %s
2+
// RUN: not %target-swift-frontend -typecheck %s
33
enum a<b> {
44
c = d macro d()
55
}
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)