Skip to content

[Sema] Extract @autoclosure diagnostics from type resolver #22348

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 6, 2019
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
21 changes: 14 additions & 7 deletions lib/Sema/CSGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1429,20 +1429,27 @@ namespace {
diag::super_with_no_base_class);
}

Type resolveTypeReferenceInExpression(TypeRepr *rep) {
Type resolveTypeReferenceInExpression(TypeRepr *repr) {
TypeLoc loc(repr);
return resolveTypeReferenceInExpression(loc);
}

Type resolveTypeReferenceInExpression(TypeLoc &loc) {
TypeResolutionOptions options(TypeResolverContext::InExpression);
options |= TypeResolutionFlags::AllowUnboundGenerics;
return TypeResolution::forContextual(CS.DC).resolveType(rep,
options);
bool hadError = CS.TC.validateType(
loc, TypeResolution::forContextual(CS.DC), options);
return hadError ? Type() : loc.getType();
}

Type visitTypeExpr(TypeExpr *E) {
Type type;
// If this is an implicit TypeExpr, don't validate its contents.
if (E->getTypeLoc().wasValidated()) {
type = E->getTypeLoc().getType();
} else if (auto *rep = E->getTypeRepr()) {
type = resolveTypeReferenceInExpression(rep);
auto &typeLoc = E->getTypeLoc();
if (typeLoc.wasValidated()) {
type = typeLoc.getType();
} else if (typeLoc.hasLocation()) {
type = resolveTypeReferenceInExpression(typeLoc);
}

if (!type || type->hasError()) return Type();
Expand Down
7 changes: 0 additions & 7 deletions lib/Sema/TypeCheckPattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -773,13 +773,6 @@ static bool validateParameterType(ParamDecl *decl, TypeResolution resolution,
}
}

// If this parameter declaration is marked as `@autoclosure`
// let's make sure that its parameter type is indeed a function,
// this decision couldn't be made based on type representative
// alone because it may be later resolved into an invalid type.
if (decl->isAutoClosure())
hadError |= !(Ty && Ty->is<FunctionType>());

if (hadError)
TL.setInvalidType(TC.Context);

Expand Down
Loading