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:
Pavel Yaskevich
2022-02-24 08:57:42 -08:00
committed by GitHub
25 changed files with 994 additions and 53 deletions

View File

@@ -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;
}