Skip to content

[Type Checker] Separate "override" checking into its own file #17694

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 2 commits into from
Jul 3, 2018
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
1 change: 1 addition & 0 deletions lib/Sema/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ add_swift_library(swiftSema STATIC
TypeCheckCircularity.cpp
TypeCheckConstraints.cpp
TypeCheckDecl.cpp
TypeCheckDeclOverride.cpp
TypeCheckError.cpp
TypeCheckExpr.cpp
TypeCheckExprObjC.cpp
Expand Down
9 changes: 5 additions & 4 deletions lib/Sema/CSDiag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "CSDiag.h"
#include "CalleeCandidateInfo.h"
#include "MiscDiagnostics.h"
#include "TypeCheckAvailability.h"
#include "TypoCorrection.h"
#include "swift/AST/ASTWalker.h"
#include "swift/AST/GenericEnvironment.h"
Expand Down Expand Up @@ -4404,7 +4405,7 @@ class ArgumentMatcher : public MatchCallArgumentListener {
assert(!newNames.empty() && "No arguments were re-labeled");

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

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

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

Expand Down
5 changes: 3 additions & 2 deletions lib/Sema/CalleeCandidateInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "ConstraintSystem.h"
#include "CSDiag.h"
#include "CalleeCandidateInfo.h"
#include "TypeCheckAvailability.h"
#include "swift/AST/GenericEnvironment.h"
#include "swift/AST/ParameterList.h"
#include "swift/AST/TypeWalker.h"
Expand Down Expand Up @@ -1057,8 +1058,8 @@ bool CalleeCandidateInfo::diagnoseSimpleErrors(const Expr *E) {
if (closeness == CC_Unavailable) {
auto decl = candidates[0].getDecl();
assert(decl && "Only decl-based candidates may be marked unavailable");
return CS.TC.diagnoseExplicitUnavailability(decl, loc, CS.DC,
dyn_cast<CallExpr>(E));
return diagnoseExplicitUnavailability(decl, loc, CS.DC,
dyn_cast<CallExpr>(E));
}

// Handle symbols that are matches, but are not accessible from the current
Expand Down
2 changes: 2 additions & 0 deletions lib/Sema/CodeSynthesis.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ void makeDynamic(ASTContext &ctx, ValueDecl *D);
void markAsObjC(TypeChecker &TC, ValueDecl *D,
Optional<ObjCReason> isObjC,
Optional<ForeignErrorConvention> errorConvention = None);

// Implemented in TypeCheckerOverride.cpp
bool checkOverrides(TypeChecker &TC, ValueDecl *decl);

// These are implemented in CodeSynthesis.cpp.
Expand Down
34 changes: 21 additions & 13 deletions lib/Sema/MiscDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1837,7 +1837,8 @@ bool TypeChecker::getDefaultGenericArgumentsString(

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

auto &diags = ctx.Diags;
auto tuple = dyn_cast<TupleExpr>(expr);
if (!tuple) {
llvm::SmallString<16> str;
Expand All @@ -1868,9 +1870,10 @@ bool swift::diagnoseArgumentLabelError(TypeChecker &TC, const Expr *expr,
str = ".";
str += field.getName().str();
if (!existingDiag) {
diagOpt.emplace(TC.diagnose(expr->getStartLoc(),
diag::extra_named_single_element_tuple,
field.getName().str()));
diagOpt.emplace(
diags.diagnose(expr->getStartLoc(),
diag::extra_named_single_element_tuple,
field.getName().str()));
}
getDiag().fixItInsertAfter(expr->getEndLoc(), str);
return true;
Expand All @@ -1894,9 +1897,10 @@ bool swift::diagnoseArgumentLabelError(TypeChecker &TC, const Expr *expr,
str += newNames[0].str();
str += ": ";
if (!existingDiag) {
diagOpt.emplace(TC.diagnose(expr->getStartLoc(),
diag::missing_argument_labels,
false, str.str().drop_back(), isSubscript));
diagOpt.emplace(diags.diagnose(expr->getStartLoc(),
diag::missing_argument_labels,
false, str.str().drop_back(),
isSubscript));
}
getDiag().fixItInsert(expr->getStartLoc(), str);
return true;
Expand Down Expand Up @@ -1962,17 +1966,21 @@ bool swift::diagnoseArgumentLabelError(TypeChecker &TC, const Expr *expr,

StringRef haveStr = haveBuffer;
StringRef expectedStr = expectedBuffer;
diagOpt.emplace(TC.diagnose(expr->getLoc(), diag::wrong_argument_labels,
plural, haveStr, expectedStr, isSubscript));
diagOpt.emplace(diags.diagnose(expr->getLoc(),
diag::wrong_argument_labels,
plural, haveStr, expectedStr,
isSubscript));
} else if (numMissing > 0) {
StringRef missingStr = missingBuffer;
diagOpt.emplace(TC.diagnose(expr->getLoc(), diag::missing_argument_labels,
plural, missingStr, isSubscript));
diagOpt.emplace(diags.diagnose(expr->getLoc(),
diag::missing_argument_labels,
plural, missingStr, isSubscript));
} else {
assert(numExtra > 0);
StringRef extraStr = extraBuffer;
diagOpt.emplace(TC.diagnose(expr->getLoc(), diag::extra_argument_labels,
plural, extraStr, isSubscript));
diagOpt.emplace(diags.diagnose(expr->getLoc(),
diag::extra_argument_labels,
plural, extraStr, isSubscript));
}
}

Expand Down
3 changes: 2 additions & 1 deletion lib/Sema/MiscDiagnostics.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ void fixItAccess(InFlightDiagnostic &diag, ValueDecl *VD,
/// error diagnostic.
///
/// \returns true if the issue was diagnosed
bool diagnoseArgumentLabelError(TypeChecker &TC, const Expr *expr,
bool diagnoseArgumentLabelError(ASTContext &ctx,
const Expr *expr,
ArrayRef<Identifier> newNames,
bool isSubscript,
InFlightDiagnostic *existingDiag = nullptr);
Expand Down
Loading