Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions lib/Sema/CSApply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
if (!var->getParsedAccessor(AccessorKind::Get)) {
if (auto opaque = var->getOpaqueResultTypeDecl()) {
SubstitutionMap 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;
});
return expr;
});

opaque->setUniqueUnderlyingTypeSubstitutions(substitutions);
opaque->setUniqueUnderlyingTypeSubstitutions(substitutions);
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions lib/Sema/TypeOfReference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1758,6 +1758,9 @@ static bool isExistentialMemberAccessWithExplicitBaseExpression(
Type ConstraintSystem::getMemberReferenceTypeFromOpenedType(
Type type, Type baseObjTy, ValueDecl *value,
ConstraintLocator *locator, bool hasAppliedSelf, bool isDynamicLookup) {
if (isa<MacroDecl>(value) || type->is<ErrorType>())
return ErrorType::get(getASTContext());

auto *outerDC = value->getDeclContext();

// Cope with dynamic 'Self'.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// {"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"}
// RUN: not --crash %target-swift-ide-test -code-completion -batch-code-completion -skip-filecheck -code-completion-diagnostics -source-filename %s
// RUN: %target-swift-ide-test -code-completion -batch-code-completion -skip-filecheck -code-completion-diagnostics -source-filename %s
enum a<b> {
c=d#^^# macro d()
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// {"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"}
// RUN: not --crash %target-swift-frontend -typecheck %s
// RUN: not %target-swift-frontend -typecheck %s
enum a<b> {
c = d macro d()
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// {"kind":"typecheck","original":"3a2652c9","signature":"(anonymous namespace)::OpaqueUnderlyingTypeChecker::check()","signatureAssert":"Assertion failed: (!UniqueUnderlyingType.has_value() && \"resetting underlying type?!\"), function setUniqueUnderlyingTypeSubstitutions"}
// RUN: not --crash %target-swift-frontend -typecheck %s
// RUN: not %target-swift-frontend -typecheck %s
var a: some Any = 0.0 {
0
}