Skip to content

Commit 4571c26

Browse files
committed
[ConstraintSystem] Teach init ref validation about implicit conversions
Implicit conversion used to erase path for contextual type conversions but it does so no longer, this means that invalid initializer reference check needs to know about existence of implicit conversions that are not reflected in the AST until solution is applied. Resolves: rdar://99352676
1 parent e5d2662 commit 4571c26

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8861,6 +8861,10 @@ static ConstraintFix *validateInitializerRef(ConstraintSystem &cs,
88618861
if (!anchor)
88628862
return nullptr;
88638863

8864+
// Avoid checking implicit conversions injected by the compiler.
8865+
if (locator->findFirst<LocatorPathElt::ImplicitConversion>())
8866+
return nullptr;
8867+
88648868
auto getType = [&cs](Expr *expr) -> Type {
88658869
return cs.simplifyType(cs.getType(expr))->getRValueType();
88668870
};

test/Constraints/implicit_double_cgfloat_conversion.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,3 +330,15 @@ func test_implicit_conversion_clash_with_partial_application_check() {
330330
}
331331
}
332332
}
333+
334+
// rdar://99352676
335+
func test_init_validation() {
336+
class Foo {
337+
static let bar = 100.0
338+
339+
func getBar() -> CGFloat? {
340+
return Self.bar
341+
// CHECK: function_ref @$s12CoreGraphics7CGFloatVyACSdcfC : $@convention(method) (Double, @thin CGFloat.Type) -> CGFloat
342+
}
343+
}
344+
}

0 commit comments

Comments
 (0)