Skip to content

Commit d141935

Browse files
committed
[ConstraintSystem] Properly cache type for literal initialization coercions
Since original implicit coercion expression is preserved in AST it needs to have its simplified type cached in the constraint system in order for AST to get the correct type when solution is fully applied. Resolves: rdar://problem/45415874 (cherry picked from commit 4197cfd)
1 parent 9cfd3c4 commit d141935

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/Sema/CSApply.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3599,6 +3599,7 @@ namespace {
35993599

36003600
literalInit->setImplicit(false);
36013601

3602+
cs.setType(expr, toType);
36023603
// Keep the coercion around, because it contains the source range
36033604
// for the original constructor call.
36043605
return expr;

test/Constraints/rdar45415874.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
final class A<T> {
4+
init(_: T) {}
5+
}
6+
7+
extension A: ExpressibleByNilLiteral where T: ExpressibleByNilLiteral {
8+
convenience init(nilLiteral: ()) {
9+
self.init(nil)
10+
}
11+
}
12+
13+
struct B {
14+
var foo: A<B?> = A(nil)
15+
}

0 commit comments

Comments
 (0)