mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Merge pull request #41436 from xedin/allow-specialization-from-default-expr
[TypeChecker] Allow inference from default expressions in certain scenarios (under a flag)
This commit is contained in:
@@ -257,6 +257,11 @@ ValueDecl *RequirementFailure::getDeclRef() const {
|
||||
return cast<ValueDecl>(getDC()->getAsDecl());
|
||||
}
|
||||
|
||||
if (contextualPurpose == CTP_DefaultParameter ||
|
||||
contextualPurpose == CTP_AutoclosureDefaultParameter) {
|
||||
return cast<ValueDecl>(getDC()->getParent()->getAsDecl());
|
||||
}
|
||||
|
||||
return getAffectedDeclFromType(contextualTy);
|
||||
}
|
||||
|
||||
@@ -8087,3 +8092,27 @@ bool SwiftToCPointerConversionInInvalidContext::diagnoseAsError() {
|
||||
paramType, callee->getDescriptiveKind(), callee->getName());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DefaultExprTypeMismatch::diagnoseAsError() {
|
||||
auto *locator = getLocator();
|
||||
|
||||
unsigned paramIdx =
|
||||
locator->castLastElementTo<LocatorPathElt::ApplyArgToParam>()
|
||||
.getParamIdx();
|
||||
|
||||
emitDiagnostic(diag::cannot_convert_default_value_type_to_argument_type,
|
||||
getFromType(), getToType(), paramIdx);
|
||||
|
||||
auto overload = getCalleeOverloadChoiceIfAvailable(locator);
|
||||
assert(overload);
|
||||
|
||||
auto *PD = getParameterList(overload->choice.getDecl())->get(paramIdx);
|
||||
|
||||
auto note = emitDiagnosticAt(PD->getLoc(), diag::default_value_declared_here);
|
||||
|
||||
if (auto *defaultExpr = PD->getTypeCheckedDefaultExpr()) {
|
||||
note.highlight(defaultExpr->getSourceRange());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user