Skip to content

Replace use of getArchetype() in diagnoseGenericParameterErrors() #1200

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 1 commit into from
Feb 5, 2016
Merged
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
31 changes: 21 additions & 10 deletions lib/Sema/CSDiag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -806,11 +806,13 @@ namespace {
struct FailedArgumentInfo {
int argumentNumber = -1; ///< Arg # at the call site.
Type parameterType = Type(); ///< Expected type at the decl site.
DeclContext *declContext = nullptr; ///< Context at the candidate declaration.

bool isValid() const { return argumentNumber != -1; }

bool operator!=(const FailedArgumentInfo &other) {
if (argumentNumber != other.argumentNumber) return true;
if (declContext != other.declContext) return true;
// parameterType can be null, and isEqual doesn't handle this.
if (!parameterType || !other.parameterType)
return parameterType.getPointer() != other.parameterType.getPointer();
Expand Down Expand Up @@ -1186,6 +1188,8 @@ CalleeCandidateInfo::evaluateCloseness(DeclContext *dc, Type candArgListType,

failureInfo.argumentNumber = argNo;
failureInfo.parameterType = paramType;
if (paramType->hasTypeParameter())
failureInfo.declContext = dc;
}
}

Expand Down Expand Up @@ -1735,18 +1739,25 @@ bool CalleeCandidateInfo::diagnoseAnyStructuralArgumentError(Expr *fnExpr,
/// archetype that has argument type errors, diagnose that error and
/// return true.
bool CalleeCandidateInfo::diagnoseGenericParameterErrors(Expr *badArgExpr) {
bool foundFailure = false;
Type paramType = failedArgument.parameterType;
Type argType = badArgExpr->getType();

if (auto genericParam = paramType->getAs<GenericTypeParamType>())
paramType = genericParam->getDecl()->getArchetype();

if (paramType->is<ArchetypeType>() && !argType->hasTypeVariable() &&
// FIXME: For protocol argument types, could add specific error
// similar to could_not_use_member_on_existential.
!argType->is<ProtocolType>() && !argType->is<ProtocolCompositionType>()) {
auto archetype = paramType->castTo<ArchetypeType>();
// FIXME: For protocol argument types, could add specific error
// similar to could_not_use_member_on_existential.
if (argType->hasTypeVariable() || argType->is<ProtocolType>() ||
argType->is<ProtocolCompositionType>())
return false;

bool foundFailure = false;
SmallVector<ArchetypeType *, 4> archetypes;
SmallVector<Type, 4> substitutions;

if (!findGenericSubstitutions(failedArgument.declContext, failedArgument.parameterType,
argType, archetypes, substitutions))
return false;

for (unsigned i = 0, c = archetypes.size(); i < c; i++) {
auto archetype = archetypes[i];
auto argType = substitutions[i];

// FIXME: Add specific error for not subclass, if the archetype has a superclass?

Expand Down