@@ -1857,7 +1857,7 @@ static void fixItAvailableAttrRename(InFlightDiagnostic &diag,
1857
1857
SourceRange referenceRange,
1858
1858
const ValueDecl *renamedDecl,
1859
1859
const AvailableAttr *attr,
1860
- const ApplyExpr *call) {
1860
+ const Expr *call) {
1861
1861
if (isa<AccessorDecl>(renamedDecl))
1862
1862
return ;
1863
1863
@@ -1877,21 +1877,21 @@ static void fixItAvailableAttrRename(InFlightDiagnostic &diag,
1877
1877
1878
1878
auto &ctx = renamedDecl->getASTContext ();
1879
1879
SourceManager &sourceMgr = ctx.SourceMgr ;
1880
-
1881
1880
if (parsed.isInstanceMember ()) {
1881
+ auto *CE = dyn_cast_or_null<CallExpr>(call);
1882
+ if (!CE)
1883
+ return ;
1884
+
1882
1885
// Replace the base of the call with the "self argument".
1883
1886
// We can only do a good job with the fix-it if we have the whole call
1884
1887
// expression.
1885
1888
// FIXME: Should we be validating the ContextName in some way?
1886
- if (!call || !isa<CallExpr>(call))
1887
- return ;
1888
-
1889
1889
unsigned selfIndex = parsed.SelfIndex .getValue ();
1890
1890
const Expr *selfExpr = nullptr ;
1891
1891
SourceLoc removeRangeStart;
1892
1892
SourceLoc removeRangeEnd;
1893
1893
1894
- auto *argExpr = call ->getArg ();
1894
+ auto *argExpr = CE ->getArg ();
1895
1895
auto argList = getOriginalArgumentList (argExpr);
1896
1896
1897
1897
size_t numElementsWithinParens = argList.args .size ();
@@ -1988,54 +1988,83 @@ static void fixItAvailableAttrRename(InFlightDiagnostic &diag,
1988
1988
selfReplace += base;
1989
1989
if (needsParens)
1990
1990
selfReplace.push_back (' )' );
1991
+
1991
1992
selfReplace.push_back (' .' );
1992
1993
selfReplace += parsed.BaseName ;
1993
- diag.fixItReplace (call->getFn ()->getSourceRange (), selfReplace);
1994
+
1995
+ diag.fixItReplace (CE->getFn ()->getSourceRange (), selfReplace);
1994
1996
1995
1997
if (!parsed.isPropertyAccessor ())
1996
1998
diag.fixItRemoveChars (removeRangeStart, removeRangeEnd);
1997
1999
1998
2000
// Continue on to diagnose any argument label renames.
1999
2001
2000
2002
} else if (parsed.BaseName == " init" && isa_and_nonnull<CallExpr>(call)) {
2003
+ auto *CE = dyn_cast<CallExpr>(call);
2004
+
2001
2005
// For initializers, replace with a "call" of the context type...but only
2002
2006
// if we know we're doing a call (rather than a first-class reference).
2003
2007
if (parsed.isMember ()) {
2004
- diag.fixItReplace (call->getFn ()->getSourceRange (), parsed.ContextName );
2005
-
2006
- } else if (auto *dotCall = dyn_cast<DotSyntaxCallExpr>(call->getFn ())) {
2008
+ diag.fixItReplace (CE->getFn ()->getSourceRange (), parsed.ContextName );
2009
+ } else if (auto *dotCall = dyn_cast<DotSyntaxCallExpr>(CE->getFn ())) {
2007
2010
SourceLoc removeLoc = dotCall->getDotLoc ();
2008
2011
if (removeLoc.isInvalid ())
2009
2012
return ;
2010
2013
2011
2014
diag.fixItRemove (SourceRange (removeLoc, dotCall->getFn ()->getEndLoc ()));
2012
- } else if (!isa<ConstructorRefCallExpr>(call ->getFn ())) {
2015
+ } else if (!isa<ConstructorRefCallExpr>(CE ->getFn ())) {
2013
2016
return ;
2014
2017
}
2015
2018
2016
2019
// Continue on to diagnose any constructor argument label renames.
2017
-
2020
+
2021
+ } else if (parsed.IsSubscript ) {
2022
+ if (auto *CE = dyn_cast_or_null<CallExpr>(call)) {
2023
+ // Renaming from CallExpr to SubscriptExpr. Remove function name and
2024
+ // replace parens with square brackets.
2025
+ diag.fixItReplace (CE->getFn ()->getEndLoc (), " [" );
2026
+ diag.fixItReplace (CE->getEndLoc (), " ]" );
2027
+ }
2018
2028
} else {
2019
2029
// Just replace the base name.
2020
2030
SmallString<64 > baseReplace;
2031
+
2021
2032
if (!parsed.ContextName .empty ()) {
2022
2033
baseReplace += parsed.ContextName ;
2023
2034
baseReplace += ' .' ;
2024
2035
}
2025
2036
baseReplace += parsed.BaseName ;
2026
- if (parsed.IsFunctionName && parsed.ArgumentLabels .empty () &&
2027
- isa<VarDecl>(renamedDecl)) {
2028
- // If we're going from a var to a function with no arguments, emit an
2029
- // empty parameter list.
2030
- baseReplace += " ()" ;
2037
+
2038
+ if (parsed.IsFunctionName && isa_and_nonnull<SubscriptExpr>(call)) {
2039
+ auto *SE = dyn_cast<SubscriptExpr>(call);
2040
+ // Renaming from SubscriptExpr to CallExpr. Insert function name and
2041
+ // replace square brackets with parens.
2042
+
2043
+ diag.fixItReplace (SE->getIndex ()->getStartLoc (),
2044
+ (" ." + baseReplace.str ()).str ());
2045
+ diag.fixItReplace (SE->getEndLoc (), " )" );
2046
+ } else {
2047
+ if (parsed.IsFunctionName && parsed.ArgumentLabels .empty () &&
2048
+ isa<VarDecl>(renamedDecl)) {
2049
+ // If we're going from a var to a function with no arguments, emit an
2050
+ // empty parameter list.
2051
+ baseReplace += " ()" ;
2052
+ }
2053
+ diag.fixItReplace (referenceRange, baseReplace);
2031
2054
}
2032
- diag.fixItReplace (referenceRange, baseReplace);
2033
2055
}
2034
2056
2035
- if (!call || !isa<CallExpr>(call))
2057
+ if (!call)
2058
+ return ;
2059
+
2060
+ Expr *argExpr;
2061
+ if (auto *CE = dyn_cast<CallExpr>(call))
2062
+ argExpr = CE->getArg ();
2063
+ else if (auto *SE = dyn_cast<SubscriptExpr>(call))
2064
+ argExpr = SE->getIndex ();
2065
+ else
2036
2066
return ;
2037
2067
2038
- auto *argExpr = call->getArg ();
2039
2068
auto argList = getOriginalArgumentList (argExpr);
2040
2069
2041
2070
if (parsed.IsGetter ) {
@@ -2148,7 +2177,8 @@ static void fixItAvailableAttrRename(InFlightDiagnostic &diag,
2148
2177
if (argList.isUnlabeledTrailingClosureIdx (i))
2149
2178
continue ;
2150
2179
if (argumentLabelIDs[i] != argList.labels [i]) {
2151
- diagnoseArgumentLabelError (ctx, argExpr, argumentLabelIDs, false , &diag);
2180
+ diagnoseArgumentLabelError (ctx, argExpr, argumentLabelIDs,
2181
+ parsed.IsSubscript , &diag);
2152
2182
return ;
2153
2183
}
2154
2184
}
@@ -2191,7 +2221,7 @@ describeRename(ASTContext &ctx, const AvailableAttr *attr, const ValueDecl *D,
2191
2221
name << parsed.ContextName << ' .' ;
2192
2222
2193
2223
if (parsed.IsFunctionName ) {
2194
- name << parsed.formDeclName (ctx);
2224
+ name << parsed.formDeclName (ctx, (D && isa<SubscriptDecl>(D)) );
2195
2225
} else {
2196
2226
name << parsed.BaseName ;
2197
2227
}
@@ -2208,7 +2238,7 @@ describeRename(ASTContext &ctx, const AvailableAttr *attr, const ValueDecl *D,
2208
2238
void TypeChecker::diagnoseIfDeprecated (SourceRange ReferenceRange,
2209
2239
const ExportContext &Where,
2210
2240
const ValueDecl *DeprecatedDecl,
2211
- const ApplyExpr *Call) {
2241
+ const Expr *Call) {
2212
2242
const AvailableAttr *Attr = TypeChecker::getDeprecated (DeprecatedDecl);
2213
2243
if (!Attr)
2214
2244
return ;
@@ -2392,10 +2422,9 @@ void swift::diagnoseUnavailableOverride(ValueDecl *override,
2392
2422
2393
2423
// / Emit a diagnostic for references to declarations that have been
2394
2424
// / marked as unavailable, either through "unavailable" or "obsoleted:".
2395
- bool swift::diagnoseExplicitUnavailability (const ValueDecl *D,
2396
- SourceRange R,
2425
+ bool swift::diagnoseExplicitUnavailability (const ValueDecl *D, SourceRange R,
2397
2426
const ExportContext &Where,
2398
- const ApplyExpr *call,
2427
+ const Expr *call,
2399
2428
DeclAvailabilityFlags Flags) {
2400
2429
return diagnoseExplicitUnavailability (D, R, Where, Flags,
2401
2430
[=](InFlightDiagnostic &diag) {
@@ -2762,7 +2791,7 @@ class ExprAvailabilityWalker : public ASTWalker {
2762
2791
diagnoseDeclRefAvailability (DS->getMember (), DS->getSourceRange ());
2763
2792
if (auto S = dyn_cast<SubscriptExpr>(E)) {
2764
2793
if (S->hasDecl ()) {
2765
- diagnoseDeclRefAvailability (S->getDecl (), S->getSourceRange ());
2794
+ diagnoseDeclRefAvailability (S->getDecl (), S->getSourceRange (), S );
2766
2795
maybeDiagStorageAccess (S->getDecl ().getDecl (), S->getSourceRange (), DC);
2767
2796
}
2768
2797
}
@@ -2820,7 +2849,7 @@ class ExprAvailabilityWalker : public ASTWalker {
2820
2849
}
2821
2850
2822
2851
bool diagnoseDeclRefAvailability (ConcreteDeclRef declRef, SourceRange R,
2823
- const ApplyExpr *call = nullptr ,
2852
+ const Expr *call = nullptr ,
2824
2853
DeclAvailabilityFlags flags = None) const ;
2825
2854
2826
2855
private:
@@ -3003,9 +3032,8 @@ class ExprAvailabilityWalker : public ASTWalker {
3003
3032
3004
3033
// / Diagnose uses of unavailable declarations. Returns true if a diagnostic
3005
3034
// / was emitted.
3006
- bool
3007
- ExprAvailabilityWalker::diagnoseDeclRefAvailability (
3008
- ConcreteDeclRef declRef, SourceRange R, const ApplyExpr *call,
3035
+ bool ExprAvailabilityWalker::diagnoseDeclRefAvailability (
3036
+ ConcreteDeclRef declRef, SourceRange R, const Expr *call,
3009
3037
DeclAvailabilityFlags Flags) const {
3010
3038
if (!declRef)
3011
3039
return false ;
@@ -3014,7 +3042,8 @@ ExprAvailabilityWalker::diagnoseDeclRefAvailability(
3014
3042
if (auto *attr = AvailableAttr::isUnavailable (D)) {
3015
3043
if (diagnoseIncDecRemoval (D, R, attr))
3016
3044
return true ;
3017
- if (call && diagnoseMemoryLayoutMigration (D, R, attr, call))
3045
+ if (isa_and_nonnull<ApplyExpr>(call) &&
3046
+ diagnoseMemoryLayoutMigration (D, R, attr, dyn_cast<ApplyExpr>(call)))
3018
3047
return true ;
3019
3048
}
3020
3049
@@ -3032,12 +3061,10 @@ ExprAvailabilityWalker::diagnoseDeclRefAvailability(
3032
3061
3033
3062
// / Diagnose uses of unavailable declarations. Returns true if a diagnostic
3034
3063
// / was emitted.
3035
- bool
3036
- swift::diagnoseDeclAvailability (const ValueDecl *D,
3037
- SourceRange R,
3038
- const ApplyExpr *call,
3039
- const ExportContext &Where,
3040
- DeclAvailabilityFlags Flags) {
3064
+ bool swift::diagnoseDeclAvailability (const ValueDecl *D, SourceRange R,
3065
+ const Expr *call,
3066
+ const ExportContext &Where,
3067
+ DeclAvailabilityFlags Flags) {
3041
3068
assert (!Where.isImplicit ());
3042
3069
3043
3070
// Generic parameters are always available.
@@ -3097,7 +3124,6 @@ swift::diagnoseDeclAvailability(const ValueDecl *D,
3097
3124
return false ;
3098
3125
}
3099
3126
3100
-
3101
3127
// / Return true if the specified type looks like an integer of floating point
3102
3128
// / type.
3103
3129
static bool isIntegerOrFloatingPointType (Type ty, ModuleDecl *M) {
0 commit comments