Skip to content

Commit 2f28b9b

Browse files
committed
AST: Don't forget to substitute opaque types in ProtocolConformance::subst()
We checked the wrong condition when deciding if a conformance should be substituted or not, so we would leave behind opaque return types in builtin and inherited conformances. This is now flagged by SubstitutionMap::verify().
1 parent 7c21789 commit 2f28b9b

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

lib/AST/ProtocolConformance.cpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -976,8 +976,7 @@ ProtocolConformance::subst(InFlightSubstitution &IFS) const {
976976
switch (getKind()) {
977977
case ProtocolConformanceKind::Normal: {
978978
auto origType = getType();
979-
if (!origType->hasTypeParameter() &&
980-
!origType->hasArchetype())
979+
if (IFS.isInvariant(origType))
981980
return ProtocolConformanceRef(mutableThis);
982981

983982
auto substType = origType.subst(IFS);
@@ -998,8 +997,7 @@ ProtocolConformance::subst(InFlightSubstitution &IFS) const {
998997

999998
case ProtocolConformanceKind::Builtin: {
1000999
auto origType = getType();
1001-
if (!origType->hasTypeParameter() &&
1002-
!origType->hasArchetype())
1000+
if (IFS.isInvariant(origType))
10031001
return ProtocolConformanceRef(mutableThis);
10041002

10051003
auto substType = origType.subst(IFS);
@@ -1022,18 +1020,14 @@ ProtocolConformance::subst(InFlightSubstitution &IFS) const {
10221020

10231021
case ProtocolConformanceKind::Inherited: {
10241022
// Substitute the base.
1025-
auto inheritedConformance
1026-
= cast<InheritedProtocolConformance>(this)->getInheritedConformance();
1027-
10281023
auto origType = getType();
1029-
if (!origType->hasTypeParameter() &&
1030-
!origType->hasArchetype()) {
1024+
if (IFS.isInvariant(origType))
10311025
return ProtocolConformanceRef(mutableThis);
1032-
}
10331026

1034-
auto origBaseType = inheritedConformance->getType();
1035-
if (origBaseType->hasTypeParameter() ||
1036-
origBaseType->hasArchetype()) {
1027+
auto inheritedConformance
1028+
= cast<InheritedProtocolConformance>(this)->getInheritedConformance();
1029+
1030+
if (!IFS.isInvariant(inheritedConformance->getType())) {
10371031
// Substitute into the superclass.
10381032
auto substConformance = inheritedConformance->subst(IFS);
10391033
if (!substConformance.isConcrete())

0 commit comments

Comments
 (0)