mirror of
https://github.com/apple/swift.git
synced 2026-02-27 18:26:24 +01:00
Remove diag::type_of_expression_is_ambiguous
This is a diagnostic that is only really emitted as a fallback when the constraint system isn't able to better diagnose the expression. It's not particulary helpful for the user, and can be often be misleading since the underlying issue might not actually be an ambiguity, and the user may well already have a type annotation. Let's instead just emit the fallback diagnostic that we emit in all other cases, asking the user to file a bug.
This commit is contained in:
@@ -4768,6 +4768,21 @@ void ConstraintSystem::diagnoseFailureFor(SyntacticElementTarget target) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (auto *wrappedVar = target.getAsUninitializedWrappedVar()) {
|
||||
auto *outerWrapper = wrappedVar->getOutermostAttachedPropertyWrapper();
|
||||
Type propertyType = wrappedVar->getInterfaceType();
|
||||
Type wrapperType = outerWrapper->getType();
|
||||
|
||||
// Emit the property wrapper fallback diagnostic
|
||||
wrappedVar->diagnose(diag::property_wrapper_incompatible_property,
|
||||
propertyType, wrapperType);
|
||||
if (auto nominal = wrapperType->getAnyNominal()) {
|
||||
nominal->diagnose(diag::property_wrapper_declared_here,
|
||||
nominal->getName());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (auto expr = target.getAsExpr()) {
|
||||
if (auto *assignment = dyn_cast<AssignExpr>(expr)) {
|
||||
if (isa<DiscardAssignmentExpr>(assignment->getDest()))
|
||||
@@ -4785,33 +4800,12 @@ void ConstraintSystem::diagnoseFailureFor(SyntacticElementTarget target) {
|
||||
.highlight(closure->getSourceRange());
|
||||
return;
|
||||
}
|
||||
|
||||
// If no one could find a problem with this expression or constraint system,
|
||||
// then it must be well-formed... but is ambiguous. Handle this by
|
||||
// diagnostic various cases that come up.
|
||||
DE.diagnose(expr->getLoc(), diag::type_of_expression_is_ambiguous)
|
||||
.highlight(expr->getSourceRange());
|
||||
} else if (auto *wrappedVar = target.getAsUninitializedWrappedVar()) {
|
||||
auto *outerWrapper = wrappedVar->getOutermostAttachedPropertyWrapper();
|
||||
Type propertyType = wrappedVar->getInterfaceType();
|
||||
Type wrapperType = outerWrapper->getType();
|
||||
|
||||
// Emit the property wrapper fallback diagnostic
|
||||
wrappedVar->diagnose(diag::property_wrapper_incompatible_property,
|
||||
propertyType, wrapperType);
|
||||
if (auto nominal = wrapperType->getAnyNominal()) {
|
||||
nominal->diagnose(diag::property_wrapper_declared_here,
|
||||
nominal->getName());
|
||||
}
|
||||
} else if (target.getAsUninitializedVar()) {
|
||||
DE.diagnose(target.getLoc(), diag::failed_to_produce_diagnostic);
|
||||
} else if (target.isForEachPreamble()) {
|
||||
DE.diagnose(target.getLoc(), diag::failed_to_produce_diagnostic);
|
||||
} else {
|
||||
// Emit a poor fallback message.
|
||||
DE.diagnose(target.getAsFunction()->getLoc(),
|
||||
diag::failed_to_produce_diagnostic);
|
||||
}
|
||||
|
||||
// Emit a poor fallback message.
|
||||
auto diag = DE.diagnose(target.getLoc(), diag::failed_to_produce_diagnostic);
|
||||
if (auto *expr = target.getAsExpr())
|
||||
diag.highlight(expr->getSourceRange());
|
||||
}
|
||||
|
||||
bool ConstraintSystem::isDeclUnavailable(const Decl *D,
|
||||
|
||||
Reference in New Issue
Block a user