Skip to content

Commit 036cf8b

Browse files
authored
Merge pull request swiftlang#74831 from slavapestov/fix-literal-regression-6.0
[6.0] AST: Fix substitution map composition edge case
2 parents 9736694 + 5685a45 commit 036cf8b

File tree

3 files changed

+36
-7
lines changed

3 files changed

+36
-7
lines changed

lib/AST/TypeSubstitution.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,23 @@ operator()(CanType dependentType, Type conformingReplacementType,
227227
conformingReplacementType, conformedProtocol,
228228
/*allowMissing=*/true);
229229
}
230-
return Subs.lookupConformance(dependentType, conformedProtocol);
230+
231+
auto result = Subs.lookupConformance(dependentType, conformedProtocol);
232+
if (!result.isInvalid())
233+
return result;
234+
235+
// Otherwise, the original type might be fixed to a concrete type in
236+
// the substitution map's input generic signature.
237+
if (auto genericSig = Subs.getGenericSignature()) {
238+
if (genericSig->isValidTypeParameter(dependentType) &&
239+
genericSig->isConcreteType(dependentType)) {
240+
return conformedProtocol->getModuleContext()->lookupConformance(
241+
conformingReplacementType, conformedProtocol,
242+
/*allowMissing=*/true);
243+
}
244+
}
245+
246+
return ProtocolConformanceRef::forInvalid();
231247
}
232248

233249
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)