Skip to content

Commit 7f262a7

Browse files
committed
[Sema] Extract @autoclosure diagnostics from type resolver
Since @autoclosure attribute is associated with declarations it makes more sense to move diagnostics to where type of the parameter has been completely resolved. This also helps to support parameters with typealiases pointing to function types without any extra logic in the resolver.
1 parent cf53143 commit 7f262a7

File tree

4 files changed

+197
-161
lines changed

4 files changed

+197
-161
lines changed

lib/Sema/CSGen.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,20 +1429,27 @@ namespace {
14291429
diag::super_with_no_base_class);
14301430
}
14311431

1432-
Type resolveTypeReferenceInExpression(TypeRepr *rep) {
1432+
Type resolveTypeReferenceInExpression(TypeRepr *repr) {
1433+
TypeLoc loc(repr);
1434+
return resolveTypeReferenceInExpression(loc);
1435+
}
1436+
1437+
Type resolveTypeReferenceInExpression(TypeLoc &loc) {
14331438
TypeResolutionOptions options(TypeResolverContext::InExpression);
14341439
options |= TypeResolutionFlags::AllowUnboundGenerics;
1435-
return TypeResolution::forContextual(CS.DC).resolveType(rep,
1436-
options);
1440+
bool hadError = CS.TC.validateType(
1441+
loc, TypeResolution::forContextual(CS.DC), options);
1442+
return hadError ? Type() : loc.getType();
14371443
}
14381444

14391445
Type visitTypeExpr(TypeExpr *E) {
14401446
Type type;
14411447
// If this is an implicit TypeExpr, don't validate its contents.
1442-
if (E->getTypeLoc().wasValidated()) {
1443-
type = E->getTypeLoc().getType();
1444-
} else if (auto *rep = E->getTypeRepr()) {
1445-
type = resolveTypeReferenceInExpression(rep);
1448+
auto &typeLoc = E->getTypeLoc();
1449+
if (typeLoc.wasValidated()) {
1450+
type = typeLoc.getType();
1451+
} else if (typeLoc.hasLocation()) {
1452+
type = resolveTypeReferenceInExpression(typeLoc);
14461453
}
14471454

14481455
if (!type || type->hasError()) return Type();

lib/Sema/TypeCheckPattern.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -773,13 +773,6 @@ static bool validateParameterType(ParamDecl *decl, TypeResolution resolution,
773773
}
774774
}
775775

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

0 commit comments

Comments
 (0)