mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Merge pull request #60883 from xedin/rdar-99352676
[ConstraintSystem] Teach `init` ref validation about implicit conversions
This commit is contained in:
@@ -8861,17 +8861,14 @@ static ConstraintFix *validateInitializerRef(ConstraintSystem &cs,
|
|||||||
if (!anchor)
|
if (!anchor)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
|
// Avoid checking implicit conversions injected by the compiler.
|
||||||
|
if (locator->findFirst<LocatorPathElt::ImplicitConversion>())
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
auto getType = [&cs](Expr *expr) -> Type {
|
auto getType = [&cs](Expr *expr) -> Type {
|
||||||
return cs.simplifyType(cs.getType(expr))->getRValueType();
|
return cs.simplifyType(cs.getType(expr))->getRValueType();
|
||||||
};
|
};
|
||||||
|
|
||||||
auto locatorEndsWith =
|
|
||||||
[](ConstraintLocator *locator,
|
|
||||||
ConstraintLocator::PathElementKind eltKind) -> bool {
|
|
||||||
auto path = locator->getPath();
|
|
||||||
return !path.empty() && path.back().getKind() == eltKind;
|
|
||||||
};
|
|
||||||
|
|
||||||
Expr *baseExpr = nullptr;
|
Expr *baseExpr = nullptr;
|
||||||
Type baseType;
|
Type baseType;
|
||||||
|
|
||||||
@@ -8928,7 +8925,7 @@ static ConstraintFix *validateInitializerRef(ConstraintSystem &cs,
|
|||||||
// member.
|
// member.
|
||||||
// We need to find type variable which represents contextual base.
|
// We need to find type variable which represents contextual base.
|
||||||
auto *baseLocator = cs.getConstraintLocator(
|
auto *baseLocator = cs.getConstraintLocator(
|
||||||
UME, locatorEndsWith(locator, ConstraintLocator::ConstructorMember)
|
UME, locator->isLastElement<LocatorPathElt::ConstructorMember>()
|
||||||
? ConstraintLocator::UnresolvedMember
|
? ConstraintLocator::UnresolvedMember
|
||||||
: ConstraintLocator::MemberRefBase);
|
: ConstraintLocator::MemberRefBase);
|
||||||
|
|
||||||
@@ -8943,7 +8940,7 @@ static ConstraintFix *validateInitializerRef(ConstraintSystem &cs,
|
|||||||
baseType = cs.simplifyType(*result)->getRValueType();
|
baseType = cs.simplifyType(*result)->getRValueType();
|
||||||
// Constraint for member base is formed as '$T.Type[.<member] = ...`
|
// Constraint for member base is formed as '$T.Type[.<member] = ...`
|
||||||
// which means MetatypeType has to be added after finding a type variable.
|
// which means MetatypeType has to be added after finding a type variable.
|
||||||
if (locatorEndsWith(baseLocator, ConstraintLocator::MemberRefBase))
|
if (baseLocator->isLastElement<LocatorPathElt::MemberRefBase>())
|
||||||
baseType = MetatypeType::get(baseType);
|
baseType = MetatypeType::get(baseType);
|
||||||
} else if (auto *keyPathExpr = getAsExpr<KeyPathExpr>(anchor)) {
|
} else if (auto *keyPathExpr = getAsExpr<KeyPathExpr>(anchor)) {
|
||||||
// Key path can't refer to initializers e.g. `\Type.init`
|
// Key path can't refer to initializers e.g. `\Type.init`
|
||||||
|
|||||||
@@ -330,3 +330,15 @@ func test_implicit_conversion_clash_with_partial_application_check() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// rdar://99352676
|
||||||
|
func test_init_validation() {
|
||||||
|
class Foo {
|
||||||
|
static let bar = 100.0
|
||||||
|
|
||||||
|
func getBar() -> CGFloat? {
|
||||||
|
return Self.bar
|
||||||
|
// CHECK: function_ref @$s12CoreGraphics7CGFloatVyACSdcfC : $@convention(method) (Double, @thin CGFloat.Type) -> CGFloat
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user