Skip to content

Commit cf5430b

Browse files
committed
---
yaml --- r: 348983 b: refs/heads/master c: fc4627d h: refs/heads/master i: 348981: b99b3f9 348979: 5ecaac0 348975: 5653a03
1 parent 2245f99 commit cf5430b

File tree

5 files changed

+34
-36
lines changed

5 files changed

+34
-36
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: d2c579d5f75e1de9649eb089de73edb4aec20d67
2+
refs/heads/master: fc4627d5c97ecf9e5028d1f640b21e4fd88d4e49
33
refs/heads/master-next: 203b3026584ecad859eb328b2e12490099409cd5
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea

trunk/lib/Sema/TypeCheckConstraints.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,12 +1345,9 @@ bool PreCheckExpression::walkToClosureExprPre(ClosureExpr *closure) {
13451345
auto *PL = closure->getParameters();
13461346

13471347
// Validate the parameters.
1348-
TypeResolutionOptions options(TypeResolverContext::ClosureExpr);
1349-
options |= TypeResolutionFlags::AllowUnspecifiedTypes;
1350-
options |= TypeResolutionFlags::AllowUnboundGenerics;
13511348
bool hadParameterError = false;
13521349

1353-
if (TC.typeCheckParameterList(PL, closure, options)) {
1350+
if (TypeChecker::typeCheckParameterList(PL)) {
13541351
// If we encounter an error validating the parameter list, don't bail.
13551352
// Instead, go on to validate any potential result type, and bail
13561353
// afterwards. This allows for better diagnostics, and keeps the

trunk/lib/Sema/TypeCheckDecl.cpp

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4124,8 +4124,7 @@ void TypeChecker::validateDecl(ValueDecl *D) {
41244124

41254125
// We want the function to be available for name lookup as soon
41264126
// as it has a valid interface type.
4127-
typeCheckParameterList(FD->getParameters(), FD,
4128-
TypeResolverContext::AbstractFunctionDecl);
4127+
typeCheckParameterList(FD->getParameters());
41294128
validateResultType(FD, FD->getBodyResultTypeLoc());
41304129
// FIXME: Roll all of this interface type computation into a request.
41314130
FD->computeType();
@@ -4150,8 +4149,7 @@ void TypeChecker::validateDecl(ValueDecl *D) {
41504149

41514150
DeclValidationRAII IBV(CD);
41524151

4153-
typeCheckParameterList(CD->getParameters(), CD,
4154-
TypeResolverContext::AbstractFunctionDecl);
4152+
typeCheckParameterList(CD->getParameters());
41554153
CD->computeType();
41564154
break;
41574155
}
@@ -4161,8 +4159,7 @@ void TypeChecker::validateDecl(ValueDecl *D) {
41614159

41624160
DeclValidationRAII IBV(DD);
41634161

4164-
typeCheckParameterList(DD->getParameters(), DD,
4165-
TypeResolverContext::AbstractFunctionDecl);
4162+
typeCheckParameterList(DD->getParameters());
41664163
DD->computeType();
41674164
break;
41684165
}
@@ -4172,8 +4169,7 @@ void TypeChecker::validateDecl(ValueDecl *D) {
41724169

41734170
DeclValidationRAII IBV(SD);
41744171

4175-
typeCheckParameterList(SD->getIndices(), SD,
4176-
TypeResolverContext::SubscriptDecl);
4172+
typeCheckParameterList(SD->getIndices());
41774173
validateResultType(SD, SD->getElementTypeLoc());
41784174
SD->computeType();
41794175

@@ -4182,14 +4178,10 @@ void TypeChecker::validateDecl(ValueDecl *D) {
41824178

41834179
case DeclKind::EnumElement: {
41844180
auto *EED = cast<EnumElementDecl>(D);
4185-
EnumDecl *ED = EED->getParentEnum();
4186-
41874181
DeclValidationRAII IBV(EED);
41884182

4189-
if (auto *PL = EED->getParameterList()) {
4190-
typeCheckParameterList(PL, ED,
4191-
TypeResolverContext::EnumElementDecl);
4192-
}
4183+
if (auto *PL = EED->getParameterList())
4184+
typeCheckParameterList(PL);
41934185

41944186
EED->computeType();
41954187
break;

trunk/lib/Sema/TypeCheckPattern.cpp

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -744,14 +744,26 @@ static bool validateTypedPattern(TypeChecker &TC,
744744
return hadError;
745745
}
746746

747-
static void validateParameterType(ParamDecl *decl, TypeResolution resolution,
748-
TypeResolutionOptions options,
749-
ASTContext &ctx) {
747+
static void validateParameterType(ParamDecl *decl) {
750748
if (auto ty = decl->getTypeLoc().getType())
751749
return;
752750

753-
auto origContext = options.getContext();
754-
options.setContext(None);
751+
auto *dc = decl->getDeclContext();
752+
auto resolution = TypeResolution::forInterface(dc);
753+
754+
TypeResolutionOptions options(None);
755+
if (isa<AbstractClosureExpr>(dc)) {
756+
options = TypeResolutionOptions(TypeResolverContext::ClosureExpr);
757+
options |= TypeResolutionFlags::AllowUnspecifiedTypes;
758+
options |= TypeResolutionFlags::AllowUnboundGenerics;
759+
} else if (isa<AbstractFunctionDecl>(dc)) {
760+
options = TypeResolutionOptions(TypeResolverContext::AbstractFunctionDecl);
761+
} else if (isa<SubscriptDecl>(dc)) {
762+
options = TypeResolutionOptions(TypeResolverContext::SubscriptDecl);
763+
} else {
764+
assert(isa<EnumElementDecl>(dc));
765+
options = TypeResolutionOptions(TypeResolverContext::EnumElementDecl);
766+
}
755767

756768
// If the element is a variadic parameter, resolve the parameter type as if
757769
// it were in non-parameter position, since we want functions to be
@@ -763,6 +775,7 @@ static void validateParameterType(ParamDecl *decl, TypeResolution resolution,
763775

764776
auto &TL = decl->getTypeLoc();
765777

778+
auto &ctx = dc->getASTContext();
766779
TypeChecker::validateType(ctx, TL, resolution, options);
767780

768781
Type Ty = TL.getType();
@@ -773,7 +786,7 @@ static void validateParameterType(ParamDecl *decl, TypeResolution resolution,
773786
}
774787

775788
// Disallow variadic parameters in enum elements.
776-
if (origContext == TypeResolverContext::EnumElementDecl) {
789+
if (options.getBaseContext() == TypeResolverContext::EnumElementDecl) {
777790
decl->diagnose(diag::enum_element_ellipsis);
778791
Ty = ErrorType::get(ctx);
779792
}
@@ -783,11 +796,7 @@ static void validateParameterType(ParamDecl *decl, TypeResolution resolution,
783796
}
784797

785798
/// Type check a parameter list.
786-
bool TypeChecker::typeCheckParameterList(ParameterList *PL,
787-
DeclContext *dc,
788-
TypeResolutionOptions options) {
789-
auto resolution = TypeResolution::forInterface(dc);
790-
799+
bool TypeChecker::typeCheckParameterList(ParameterList *PL) {
791800
bool hadError = false;
792801

793802
for (auto param : *PL) {
@@ -798,7 +807,7 @@ bool TypeChecker::typeCheckParameterList(ParameterList *PL,
798807
continue;
799808
}
800809

801-
validateParameterType(param, resolution, options, Context);
810+
validateParameterType(param);
802811

803812
auto type = param->getTypeLoc().getType();
804813
param->setInterfaceType(type);
@@ -825,9 +834,10 @@ bool TypeChecker::typeCheckParameterList(ParameterList *PL,
825834

826835
if (isa<InOutTypeRepr>(nestedRepr) &&
827836
param->isDefaultArgument()) {
828-
diagnose(param->getDefaultValue()->getLoc(),
829-
swift::diag::cannot_provide_default_value_inout,
830-
param->getName());
837+
auto &ctx = param->getASTContext();
838+
ctx.Diags.diagnose(param->getDefaultValue()->getLoc(),
839+
swift::diag::cannot_provide_default_value_inout,
840+
param->getName());
831841
param->setSpecifier(ParamDecl::Specifier::Default);
832842
}
833843
}

trunk/lib/Sema/TypeChecker.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,8 +1354,7 @@ class TypeChecker final : public LazyResolver {
13541354
bool typeCheckCatchPattern(CatchStmt *S, DeclContext *dc);
13551355

13561356
/// Type check a parameter list.
1357-
bool typeCheckParameterList(ParameterList *PL, DeclContext *dc,
1358-
TypeResolutionOptions options);
1357+
static bool typeCheckParameterList(ParameterList *PL);
13591358

13601359
/// Coerce a pattern to the given type.
13611360
///

0 commit comments

Comments
 (0)