Skip to content

Commit 4b711b6

Browse files
committed
AST: Fix up ReplaceOpaqueTypesWithUnderlyingTypes::operator()
This was constructing abstract conformances with the wrong subject type.
1 parent b53b770 commit 4b711b6

File tree

2 files changed

+36
-22
lines changed

2 files changed

+36
-22
lines changed

lib/AST/TypeSubstitution.cpp

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,37 +1108,23 @@ ProtocolConformanceRef swift::substOpaqueTypesWithUnderlyingTypes(
11081108
ProtocolConformanceRef ReplaceOpaqueTypesWithUnderlyingTypes::
11091109
operator()(CanType maybeOpaqueType, Type replacementType,
11101110
ProtocolDecl *protocol) const {
1111-
auto abstractRef = ProtocolConformanceRef::forAbstract(maybeOpaqueType, protocol);
1112-
11131111
auto archetype = dyn_cast<OpaqueTypeArchetypeType>(maybeOpaqueType);
1114-
if (!archetype) {
1115-
if (maybeOpaqueType->isTypeParameter() ||
1116-
maybeOpaqueType->is<ArchetypeType>())
1117-
return abstractRef;
1118-
1119-
// SIL type lowering may have already substituted away the opaque type, in
1120-
// which case we'll end up "substituting" the same type.
1121-
if (maybeOpaqueType->isEqual(replacementType)) {
1122-
return lookupConformance(replacementType, protocol);
1123-
}
1124-
1125-
llvm_unreachable("origType should have been an opaque type or type parameter");
1126-
}
1112+
if (!archetype)
1113+
return lookupConformance(replacementType, protocol);
11271114

11281115
auto *genericEnv = archetype->getGenericEnvironment();
11291116
auto *decl = genericEnv->getOpaqueTypeDecl();
11301117
auto outerSubs = genericEnv->getOuterSubstitutions();
11311118

11321119
auto substitutionKind = shouldPerformSubstitution(decl);
1133-
if (substitutionKind == OpaqueSubstitutionKind::DontSubstitute) {
1134-
return abstractRef;
1135-
}
1120+
if (substitutionKind == OpaqueSubstitutionKind::DontSubstitute)
1121+
return lookupConformance(replacementType, protocol);
11361122

11371123
auto subs = decl->getUniqueUnderlyingTypeSubstitutions();
11381124
// If the body of the opaque decl providing decl has not been type checked we
11391125
// don't have a underlying substitution.
11401126
if (!subs.has_value())
1141-
return abstractRef;
1127+
return lookupConformance(replacementType, protocol);
11421128

11431129
// Apply the underlying type substitutions to the interface type of the
11441130
// archetype in question. This will map the inner generic signature of the
@@ -1159,7 +1145,7 @@ operator()(CanType maybeOpaqueType, Type replacementType,
11591145
return true;
11601146
return false;
11611147
}))
1162-
return abstractRef;
1148+
return lookupConformance(replacementType, protocol);
11631149

11641150
// Then apply the substitutions from the root opaque archetype, to specialize
11651151
// for its type arguments. We perform this substitution after checking for
@@ -1168,7 +1154,8 @@ operator()(CanType maybeOpaqueType, Type replacementType,
11681154
auto substTy = partialSubstTy.subst(outerSubs);
11691155

11701156
auto partialSubstRef =
1171-
abstractRef.subst(archetype->getInterfaceType(), *subs);
1157+
subs->lookupConformance(archetype->getInterfaceType()->getCanonicalType(),
1158+
protocol);
11721159
auto substRef =
11731160
partialSubstRef.subst(partialSubstTy, outerSubs);
11741161

@@ -1181,7 +1168,7 @@ operator()(CanType maybeOpaqueType, Type replacementType,
11811168
// type back to the caller. This substitution will fail at runtime
11821169
// instead.
11831170
if (!alreadySeen->insert(seenKey).second) {
1184-
return abstractRef;
1171+
return lookupConformance(replacementType, protocol);
11851172
}
11861173

11871174
auto res = ::substOpaqueTypesWithUnderlyingTypesRec(
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// RUN: %target-swift-frontend -emit-silgen %s -target %target-cpu-apple-macosx11 -swift-version 5
2+
3+
// REQUIRES: objc_interop
4+
// REQUIRES: OS=macosx
5+
6+
import SwiftUI
7+
8+
struct MyView: View {
9+
@State private var isPresented = false
10+
11+
var body: some View {
12+
NavigationView {
13+
Form {
14+
subsection
15+
}
16+
.listStyle(DefaultListStyle())
17+
.navigationTitle(Text(""))
18+
.sheet(isPresented: $isPresented,
19+
onDismiss: { },
20+
content: { Text("") })
21+
}
22+
}
23+
24+
private var subsection: some View {
25+
Text("")
26+
}
27+
}

0 commit comments

Comments
 (0)