mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[CSSimplify] Implement logic for an implicit conversion to/from CGFloat
To support implicit conversion to/from CGFloat type we need to: - Reference an `init` member on the right-hand side type (either CGFloat if we are converting to it, or compatible type if from). - Add a `ApplicableFunction` constraint to model an implicit call to previously referenced initializer with an argument of left-hand side type.
This commit is contained in:
@@ -10490,7 +10490,28 @@ ConstraintSystem::simplifyRestrictedConstraintImpl(
|
||||
|
||||
case ConversionRestrictionKind::TypeToCGFloat:
|
||||
case ConversionRestrictionKind::CGFloatToType: {
|
||||
llvm_unreachable("not yet implemented");
|
||||
increaseScore(SK_ImplicitValueConversion);
|
||||
if (worseThanBestSolution())
|
||||
return SolutionKind::Error;
|
||||
|
||||
auto *applicationLoc = getConstraintLocator(
|
||||
locator, {LocatorPathElt::ImplicitConversion(restriction),
|
||||
ConstraintLocator::ApplyFunction});
|
||||
|
||||
auto *memberLoc = getConstraintLocator(
|
||||
applicationLoc, ConstraintLocator::ConstructorMember);
|
||||
|
||||
auto *memberTy = createTypeVariable(memberLoc, TVO_CanBindToNoEscape);
|
||||
|
||||
addValueMemberConstraint(MetatypeType::get(type2, getASTContext()),
|
||||
DeclNameRef(DeclBaseName::createConstructor()),
|
||||
memberTy, DC, FunctionRefKind::DoubleApply,
|
||||
/*outerAlternatives=*/{}, memberLoc);
|
||||
|
||||
addConstraint(ConstraintKind::ApplicableFunction,
|
||||
FunctionType::get({FunctionType::Param(type1)}, type2),
|
||||
memberTy, applicationLoc);
|
||||
return SolutionKind::Solved;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user