[Diagnostics] Add a tailored diagnostic for no accessible initializers

This commit is contained in:
Pavel Yaskevich
2019-08-22 17:22:18 -07:00
parent fa9c3f3a10
commit fbb55ce5bc
3 changed files with 23 additions and 1 deletions

View File

@@ -2899,6 +2899,27 @@ bool MissingMemberFailure::diagnoseAsError() {
diagnostic.highlight(baseExpr->getSourceRange())
.highlight(nameLoc.getSourceRange());
correction->addFixits(diagnostic);
} else if (instanceTy->getAnyNominal() &&
getName().getBaseName() == DeclBaseName::createConstructor()) {
auto &cs = getConstraintSystem();
auto memberName = getName().getBaseName();
auto result = cs.performMemberLookup(
ConstraintKind::ValueMember, memberName, metatypeTy,
FunctionRefKind::DoubleApply, getLocator(),
/*includeInaccessibleMembers=*/true);
// If there are no `init` members at all produce a tailored
// diagnostic for that, otherwise fallback to generic
// "no such member" one.
if (result.ViableCandidates.empty() &&
result.UnviableCandidates.empty()) {
emitDiagnostic(anchor->getLoc(), diag::no_accessible_initializers,
instanceTy)
.highlight(baseExpr->getSourceRange());
} else {
emitBasicError(baseType);
}
} else {
emitBasicError(baseType);
}