Skip to content

Commit e2607b3

Browse files
authored
Merge pull request swiftlang#34178 from LucianoPAlmeida/fixme-generic-arguments-failure
[NFC][CSDiagnostics] Improve non-scoped MissingGenericArgumentsFailure code
2 parents 563c99b + 6ceda75 commit e2607b3

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5271,14 +5271,10 @@ bool MissingGenericArgumentsFailure::diagnoseAsError() {
52715271
scopedParameters[base].push_back(GP);
52725272
});
52735273

5274-
// FIXME: this code should be generalized now that we can anchor the
5275-
// fixes on the TypeRepr with the missing generic arg.
52765274
if (!isScoped) {
5277-
assert(getAnchor().is<Expr *>() || getAnchor().is<TypeRepr *>());
5278-
if (auto *expr = getAsExpr(getAnchor()))
5279-
return diagnoseForAnchor(expr, Parameters);
5280-
5281-
return diagnoseForAnchor(getAnchor().get<TypeRepr *>(), Parameters);
5275+
auto anchor = getAnchor();
5276+
assert(anchor.is<Expr *>() || anchor.is<TypeRepr *>());
5277+
return diagnoseForAnchor(anchor, Parameters);
52825278
}
52835279

52845280
bool diagnosed = false;
@@ -5288,7 +5284,7 @@ bool MissingGenericArgumentsFailure::diagnoseAsError() {
52885284
}
52895285

52905286
bool MissingGenericArgumentsFailure::diagnoseForAnchor(
5291-
Anchor anchor, ArrayRef<GenericTypeParamType *> params) const {
5287+
ASTNode anchor, ArrayRef<GenericTypeParamType *> params) const {
52925288
bool diagnosed = false;
52935289
for (auto *GP : params)
52945290
diagnosed |= diagnoseParameter(anchor, GP);
@@ -5322,11 +5318,9 @@ bool MissingGenericArgumentsFailure::diagnoseForAnchor(
53225318
}
53235319

53245320
bool MissingGenericArgumentsFailure::diagnoseParameter(
5325-
Anchor anchor, GenericTypeParamType *GP) const {
5321+
ASTNode anchor, GenericTypeParamType *GP) const {
53265322
auto &solution = getSolution();
5327-
5328-
auto loc = anchor.is<Expr *>() ? anchor.get<Expr *>()->getLoc()
5329-
: anchor.get<TypeRepr *>()->getLoc();
5323+
auto loc = ::getLoc(anchor);
53305324

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

53745368
void MissingGenericArgumentsFailure::emitGenericSignatureNote(
5375-
Anchor anchor) const {
5369+
ASTNode anchor) const {
53765370
auto &solution = getSolution();
53775371
auto *paramDC = getDeclContext();
53785372

lib/Sema/CSDiagnostics.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,8 +1698,6 @@ class InOutConversionFailure final : public ContextualFailure {
16981698
/// _ = S()
16991699
/// ```
17001700
class MissingGenericArgumentsFailure final : public FailureDiagnostic {
1701-
using Anchor = llvm::PointerUnion<TypeRepr *, Expr *>;
1702-
17031701
SmallVector<GenericTypeParamType *, 4> Parameters;
17041702

17051703
public:
@@ -1722,13 +1720,13 @@ class MissingGenericArgumentsFailure final : public FailureDiagnostic {
17221720

17231721
bool diagnoseAsError() override;
17241722

1725-
bool diagnoseForAnchor(Anchor anchor,
1723+
bool diagnoseForAnchor(ASTNode anchor,
17261724
ArrayRef<GenericTypeParamType *> params) const;
17271725

1728-
bool diagnoseParameter(Anchor anchor, GenericTypeParamType *GP) const;
1726+
bool diagnoseParameter(ASTNode anchor, GenericTypeParamType *GP) const;
17291727

17301728
private:
1731-
void emitGenericSignatureNote(Anchor anchor) const;
1729+
void emitGenericSignatureNote(ASTNode anchor) const;
17321730

17331731
/// Retrieve representative locations for associated generic prameters.
17341732
///

0 commit comments

Comments
 (0)