Skip to content

Commit ae7183e

Browse files
authored
Merge pull request swiftlang#74828 from slavapestov/fix-literal-regression
AST: Fix substitution map composition edge case
2 parents 44779bf + 7a8a562 commit ae7183e

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed

lib/AST/TypeSubstitution.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,14 +200,29 @@ operator()(CanType dependentType, Type conformingReplacementType,
200200
ProtocolConformanceRef LookUpConformanceInSubstitutionMap::
201201
operator()(CanType dependentType, Type conformingReplacementType,
202202
ProtocolDecl *conformedProtocol) const {
203+
auto result = Subs.lookupConformance(dependentType, conformedProtocol);
204+
if (!result.isInvalid())
205+
return result;
206+
203207
// Lookup conformances for archetypes that conform concretely
204208
// via a superclass.
205209
if (auto archetypeType = conformingReplacementType->getAs<ArchetypeType>()) {
206210
return conformedProtocol->getModuleContext()->lookupConformance(
207211
conformingReplacementType, conformedProtocol,
208212
/*allowMissing=*/true);
209213
}
210-
return Subs.lookupConformance(dependentType, conformedProtocol);
214+
215+
// Otherwise, the original type might be fixed to a concrete type in
216+
// the substitution map's input generic signature.
217+
if (auto genericSig = Subs.getGenericSignature()) {
218+
if (genericSig->isConcreteType(dependentType)) {
219+
return conformedProtocol->getModuleContext()->lookupConformance(
220+
conformingReplacementType, conformedProtocol,
221+
/*allowMissing=*/true);
222+
}
223+
}
224+
225+
return ProtocolConformanceRef::forInvalid();
211226
}
212227

213228
ProtocolConformanceRef MakeAbstractConformanceForGenericType::
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %target-swift-emit-silgen %s
2+
3+
public protocol P {
4+
associatedtype A : Equatable
5+
}
6+
7+
public struct G<A: Equatable>: P {}
8+
9+
extension P where A == Int {
10+
public init(integerLiteral: Int) {
11+
fatalError()
12+
}
13+
}
14+
15+
extension G: ExpressibleByIntegerLiteral where A == Int {}
16+
17+
public func f() -> G<Int> {
18+
return 123
19+
}

validation-test/compiler_crashers_2_fixed/0022-rdar21625478.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
// RUN: %target-swift-frontend %s -emit-silgen
22

3-
// rdar://80395274 tracks getting this to pass with the requirement machine.
4-
// XFAIL: *
5-
6-
// The test hangs in a noassert build:
7-
// REQUIRES: asserts
8-
93
import StdlibUnittest
104

115
public struct MyRange<Bound : ForwardIndex> {

0 commit comments

Comments
 (0)