Skip to content

[NFC][CSDiagnostics] Improve non-scoped MissingGenericArgumentsFailure code #34178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions lib/Sema/CSDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5271,14 +5271,10 @@ bool MissingGenericArgumentsFailure::diagnoseAsError() {
scopedParameters[base].push_back(GP);
});

// FIXME: this code should be generalized now that we can anchor the
// fixes on the TypeRepr with the missing generic arg.
if (!isScoped) {
assert(getAnchor().is<Expr *>() || getAnchor().is<TypeRepr *>());
if (auto *expr = getAsExpr(getAnchor()))
return diagnoseForAnchor(expr, Parameters);

return diagnoseForAnchor(getAnchor().get<TypeRepr *>(), Parameters);
auto anchor = getAnchor();
assert(anchor.is<Expr *>() || anchor.is<TypeRepr *>());
return diagnoseForAnchor(anchor, Parameters);
}

bool diagnosed = false;
Expand All @@ -5288,7 +5284,7 @@ bool MissingGenericArgumentsFailure::diagnoseAsError() {
}

bool MissingGenericArgumentsFailure::diagnoseForAnchor(
Anchor anchor, ArrayRef<GenericTypeParamType *> params) const {
ASTNode anchor, ArrayRef<GenericTypeParamType *> params) const {
bool diagnosed = false;
for (auto *GP : params)
diagnosed |= diagnoseParameter(anchor, GP);
Expand Down Expand Up @@ -5322,11 +5318,9 @@ bool MissingGenericArgumentsFailure::diagnoseForAnchor(
}

bool MissingGenericArgumentsFailure::diagnoseParameter(
Anchor anchor, GenericTypeParamType *GP) const {
ASTNode anchor, GenericTypeParamType *GP) const {
auto &solution = getSolution();

auto loc = anchor.is<Expr *>() ? anchor.get<Expr *>()->getLoc()
: anchor.get<TypeRepr *>()->getLoc();
auto loc = ::getLoc(anchor);

auto *locator = getLocator();
// Type variables associated with missing generic parameters are
Expand Down Expand Up @@ -5372,7 +5366,7 @@ bool MissingGenericArgumentsFailure::diagnoseParameter(
}

void MissingGenericArgumentsFailure::emitGenericSignatureNote(
Anchor anchor) const {
ASTNode anchor) const {
auto &solution = getSolution();
auto *paramDC = getDeclContext();

Expand Down
8 changes: 3 additions & 5 deletions lib/Sema/CSDiagnostics.h
Original file line number Diff line number Diff line change
Expand Up @@ -1698,8 +1698,6 @@ class InOutConversionFailure final : public ContextualFailure {
/// _ = S()
/// ```
class MissingGenericArgumentsFailure final : public FailureDiagnostic {
using Anchor = llvm::PointerUnion<TypeRepr *, Expr *>;

SmallVector<GenericTypeParamType *, 4> Parameters;

public:
Expand All @@ -1722,13 +1720,13 @@ class MissingGenericArgumentsFailure final : public FailureDiagnostic {

bool diagnoseAsError() override;

bool diagnoseForAnchor(Anchor anchor,
bool diagnoseForAnchor(ASTNode anchor,
ArrayRef<GenericTypeParamType *> params) const;

bool diagnoseParameter(Anchor anchor, GenericTypeParamType *GP) const;
bool diagnoseParameter(ASTNode anchor, GenericTypeParamType *GP) const;

private:
void emitGenericSignatureNote(Anchor anchor) const;
void emitGenericSignatureNote(ASTNode anchor) const;

/// Retrieve representative locations for associated generic prameters.
///
Expand Down