Skip to content

Commit 0fcaef1

Browse files
authored
Merge pull request #17694 from DougGregor/separate-override-checking
2 parents e3aa53c + 80688d0 commit 0fcaef1

13 files changed

+1739
-1663
lines changed

lib/Sema/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ add_swift_library(swiftSema STATIC
3939
TypeCheckCircularity.cpp
4040
TypeCheckConstraints.cpp
4141
TypeCheckDecl.cpp
42+
TypeCheckDeclOverride.cpp
4243
TypeCheckError.cpp
4344
TypeCheckExpr.cpp
4445
TypeCheckExprObjC.cpp

lib/Sema/CSDiag.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "CSDiag.h"
1919
#include "CalleeCandidateInfo.h"
2020
#include "MiscDiagnostics.h"
21+
#include "TypeCheckAvailability.h"
2122
#include "TypoCorrection.h"
2223
#include "swift/AST/ASTWalker.h"
2324
#include "swift/AST/GenericEnvironment.h"
@@ -4404,7 +4405,7 @@ class ArgumentMatcher : public MatchCallArgumentListener {
44044405
assert(!newNames.empty() && "No arguments were re-labeled");
44054406

44064407
// Let's diagnose labeling problem but only related to corrected ones.
4407-
if (diagnoseArgumentLabelError(TC, ArgExpr, newNames, IsSubscript))
4408+
if (diagnoseArgumentLabelError(TC.Context, ArgExpr, newNames, IsSubscript))
44084409
Diagnosed = true;
44094410

44104411
return true;
@@ -6351,7 +6352,7 @@ bool FailureDiagnosis::visitCoerceExpr(CoerceExpr *CE) {
63516352
// type-checking sub-expression as unavaible
63526353
// declaration, let's try to diagnose that here.
63536354
if (AvailableAttr::isUnavailable(decl))
6354-
return CS.TC.diagnoseExplicitUnavailability(
6355+
return diagnoseExplicitUnavailability(
63556356
decl, expr->getSourceRange(), CS.DC, dyn_cast<ApplyExpr>(expr));
63566357
}
63576358

@@ -7908,8 +7909,8 @@ bool FailureDiagnosis::diagnoseMemberFailures(
79087909
if (allUnavailable) {
79097910
auto firstDecl = viableCandidatesToReport[0].getDecl();
79107911
// FIXME: We need the enclosing CallExpr to rewrite the argument labels.
7911-
if (CS.TC.diagnoseExplicitUnavailability(firstDecl, BaseLoc, CS.DC,
7912-
/*call*/ nullptr))
7912+
if (diagnoseExplicitUnavailability(firstDecl, BaseLoc, CS.DC,
7913+
/*call*/ nullptr))
79137914
return true;
79147915
}
79157916

lib/Sema/CalleeCandidateInfo.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "ConstraintSystem.h"
1818
#include "CSDiag.h"
1919
#include "CalleeCandidateInfo.h"
20+
#include "TypeCheckAvailability.h"
2021
#include "swift/AST/GenericEnvironment.h"
2122
#include "swift/AST/ParameterList.h"
2223
#include "swift/AST/TypeWalker.h"
@@ -1057,8 +1058,8 @@ bool CalleeCandidateInfo::diagnoseSimpleErrors(const Expr *E) {
10571058
if (closeness == CC_Unavailable) {
10581059
auto decl = candidates[0].getDecl();
10591060
assert(decl && "Only decl-based candidates may be marked unavailable");
1060-
return CS.TC.diagnoseExplicitUnavailability(decl, loc, CS.DC,
1061-
dyn_cast<CallExpr>(E));
1061+
return diagnoseExplicitUnavailability(decl, loc, CS.DC,
1062+
dyn_cast<CallExpr>(E));
10621063
}
10631064

10641065
// Handle symbols that are matches, but are not accessible from the current

lib/Sema/CodeSynthesis.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ void makeDynamic(ASTContext &ctx, ValueDecl *D);
9898
void markAsObjC(TypeChecker &TC, ValueDecl *D,
9999
Optional<ObjCReason> isObjC,
100100
Optional<ForeignErrorConvention> errorConvention = None);
101+
102+
// Implemented in TypeCheckerOverride.cpp
101103
bool checkOverrides(TypeChecker &TC, ValueDecl *decl);
102104

103105
// These are implemented in CodeSynthesis.cpp.

lib/Sema/MiscDiagnostics.cpp

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1837,7 +1837,8 @@ bool TypeChecker::getDefaultGenericArgumentsString(
18371837

18381838
/// Diagnose an argument labeling issue, returning true if we successfully
18391839
/// diagnosed the issue.
1840-
bool swift::diagnoseArgumentLabelError(TypeChecker &TC, const Expr *expr,
1840+
bool swift::diagnoseArgumentLabelError(ASTContext &ctx,
1841+
const Expr *expr,
18411842
ArrayRef<Identifier> newNames,
18421843
bool isSubscript,
18431844
InFlightDiagnostic *existingDiag) {
@@ -1848,6 +1849,7 @@ bool swift::diagnoseArgumentLabelError(TypeChecker &TC, const Expr *expr,
18481849
return *diagOpt;
18491850
};
18501851

1852+
auto &diags = ctx.Diags;
18511853
auto tuple = dyn_cast<TupleExpr>(expr);
18521854
if (!tuple) {
18531855
llvm::SmallString<16> str;
@@ -1868,9 +1870,10 @@ bool swift::diagnoseArgumentLabelError(TypeChecker &TC, const Expr *expr,
18681870
str = ".";
18691871
str += field.getName().str();
18701872
if (!existingDiag) {
1871-
diagOpt.emplace(TC.diagnose(expr->getStartLoc(),
1872-
diag::extra_named_single_element_tuple,
1873-
field.getName().str()));
1873+
diagOpt.emplace(
1874+
diags.diagnose(expr->getStartLoc(),
1875+
diag::extra_named_single_element_tuple,
1876+
field.getName().str()));
18741877
}
18751878
getDiag().fixItInsertAfter(expr->getEndLoc(), str);
18761879
return true;
@@ -1894,9 +1897,10 @@ bool swift::diagnoseArgumentLabelError(TypeChecker &TC, const Expr *expr,
18941897
str += newNames[0].str();
18951898
str += ": ";
18961899
if (!existingDiag) {
1897-
diagOpt.emplace(TC.diagnose(expr->getStartLoc(),
1898-
diag::missing_argument_labels,
1899-
false, str.str().drop_back(), isSubscript));
1900+
diagOpt.emplace(diags.diagnose(expr->getStartLoc(),
1901+
diag::missing_argument_labels,
1902+
false, str.str().drop_back(),
1903+
isSubscript));
19001904
}
19011905
getDiag().fixItInsert(expr->getStartLoc(), str);
19021906
return true;
@@ -1962,17 +1966,21 @@ bool swift::diagnoseArgumentLabelError(TypeChecker &TC, const Expr *expr,
19621966

19631967
StringRef haveStr = haveBuffer;
19641968
StringRef expectedStr = expectedBuffer;
1965-
diagOpt.emplace(TC.diagnose(expr->getLoc(), diag::wrong_argument_labels,
1966-
plural, haveStr, expectedStr, isSubscript));
1969+
diagOpt.emplace(diags.diagnose(expr->getLoc(),
1970+
diag::wrong_argument_labels,
1971+
plural, haveStr, expectedStr,
1972+
isSubscript));
19671973
} else if (numMissing > 0) {
19681974
StringRef missingStr = missingBuffer;
1969-
diagOpt.emplace(TC.diagnose(expr->getLoc(), diag::missing_argument_labels,
1970-
plural, missingStr, isSubscript));
1975+
diagOpt.emplace(diags.diagnose(expr->getLoc(),
1976+
diag::missing_argument_labels,
1977+
plural, missingStr, isSubscript));
19711978
} else {
19721979
assert(numExtra > 0);
19731980
StringRef extraStr = extraBuffer;
1974-
diagOpt.emplace(TC.diagnose(expr->getLoc(), diag::extra_argument_labels,
1975-
plural, extraStr, isSubscript));
1981+
diagOpt.emplace(diags.diagnose(expr->getLoc(),
1982+
diag::extra_argument_labels,
1983+
plural, extraStr, isSubscript));
19761984
}
19771985
}
19781986

lib/Sema/MiscDiagnostics.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ void fixItAccess(InFlightDiagnostic &diag, ValueDecl *VD,
6161
/// error diagnostic.
6262
///
6363
/// \returns true if the issue was diagnosed
64-
bool diagnoseArgumentLabelError(TypeChecker &TC, const Expr *expr,
64+
bool diagnoseArgumentLabelError(ASTContext &ctx,
65+
const Expr *expr,
6566
ArrayRef<Identifier> newNames,
6667
bool isSubscript,
6768
InFlightDiagnostic *existingDiag = nullptr);

0 commit comments

Comments
 (0)