Skip to content

Commit b99b3f9

Browse files
committed
---
yaml --- r: 348981 b: refs/heads/master c: de8745b h: refs/heads/master i: 348979: 5ecaac0
1 parent e67a0e3 commit b99b3f9

File tree

6 files changed

+47
-65
lines changed

6 files changed

+47
-65
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: 29caee2ba68dfb3fae133e4a4d7ddd876d63fc2e
2+
refs/heads/master: de8745b73390566bdb0aad94091627c26b5a20e0
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/TypeCheckPattern.cpp

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

747-
static bool validateParameterType(ParamDecl *decl, TypeResolution resolution,
747+
static void validateParameterType(ParamDecl *decl, TypeResolution resolution,
748748
TypeResolutionOptions options,
749-
TypeChecker &TC) {
749+
ASTContext &ctx) {
750750
if (auto ty = decl->getTypeLoc().getType())
751-
return ty->hasError();
751+
return;
752752

753753
auto origContext = options.getContext();
754754
options.setContext(None);
@@ -761,35 +761,25 @@ static bool validateParameterType(ParamDecl *decl, TypeResolution resolution,
761761
TypeResolverContext::FunctionInput);
762762
options |= TypeResolutionFlags::Direct;
763763

764-
bool hadError = false;
765-
766764
auto &TL = decl->getTypeLoc();
767765

768-
// We might have a null typeLoc if this is a closure parameter list,
769-
// where parameters are allowed to elide their types.
770-
if (!TL.isNull()) {
771-
hadError |= TypeChecker::validateType(TC.Context, TL, resolution, options);
772-
}
766+
TypeChecker::validateType(ctx, TL, resolution, options);
773767

774768
Type Ty = TL.getType();
775-
if (decl->isVariadic() && !Ty.isNull() && !hadError) {
776-
Ty = TC.getArraySliceType(decl->getStartLoc(), Ty);
769+
if (decl->isVariadic()) {
770+
Ty = TypeChecker::getArraySliceType(decl->getStartLoc(), Ty);
777771
if (Ty.isNull()) {
778-
hadError = true;
772+
Ty = ErrorType::get(ctx);
779773
}
780-
TL.setType(Ty);
781774

782775
// Disallow variadic parameters in enum elements.
783-
if (!hadError && origContext == TypeResolverContext::EnumElementDecl) {
784-
TC.diagnose(decl->getStartLoc(), diag::enum_element_ellipsis);
785-
hadError = true;
776+
if (origContext == TypeResolverContext::EnumElementDecl) {
777+
decl->diagnose(diag::enum_element_ellipsis);
778+
Ty = ErrorType::get(ctx);
786779
}
787-
}
788-
789-
if (hadError)
790-
TL.setInvalidType(TC.Context);
791780

792-
return hadError;
781+
TL.setType(Ty);
782+
}
793783
}
794784

795785
/// Type check a parameter list.
@@ -802,60 +792,43 @@ bool TypeChecker::typeCheckParameterList(ParameterList *PL,
802792

803793
for (auto param : *PL) {
804794
auto typeRepr = param->getTypeLoc().getTypeRepr();
805-
if (!typeRepr &&
806-
param->hasInterfaceType()) {
807-
hadError |= param->isInvalid();
795+
if (!typeRepr) {
796+
if (param->hasInterfaceType())
797+
hadError |= param->isInvalid();
808798
continue;
809799
}
810800

811-
hadError |= validateParameterType(param, resolution, options, *this);
801+
validateParameterType(param, resolution, options, Context);
812802

813803
auto type = param->getTypeLoc().getType();
804+
param->setInterfaceType(type);
814805

815-
// If there was no type specified, and if we're not looking at a
816-
// ClosureExpr, then we have a parse error (no type was specified). The
817-
// parser will have already diagnosed this, but treat this as a type error
818-
// as well to get the ParamDecl marked invalid and to get an ErrorType.
819-
if (!type) {
820-
// Closure argument lists are allowed to be missing types.
821-
if (options.isAnyExpr())
822-
continue;
823-
param->setInvalid();
824-
}
825-
826-
if (param->isInvalid() || type->hasError()) {
827-
param->markInvalid();
828-
hadError = true;
829-
} else {
830-
param->setInterfaceType(type);
831-
}
806+
hadError |= param->isInvalid();
832807

833-
if (!hadError) {
834-
auto *nestedRepr = typeRepr;
835-
836-
// Look through parens here; other than parens, specifiers
837-
// must appear at the top level of a parameter type.
838-
while (auto *tupleRepr = dyn_cast<TupleTypeRepr>(nestedRepr)) {
839-
if (!tupleRepr->isParenType())
840-
break;
841-
nestedRepr = tupleRepr->getElementType(0);
842-
}
808+
auto *nestedRepr = typeRepr;
843809

844-
if (isa<InOutTypeRepr>(nestedRepr)) {
845-
param->setSpecifier(ParamDecl::Specifier::InOut);
846-
} else if (isa<SharedTypeRepr>(nestedRepr)) {
847-
param->setSpecifier(ParamDecl::Specifier::Shared);
848-
} else if (isa<OwnedTypeRepr>(nestedRepr)) {
849-
param->setSpecifier(ParamDecl::Specifier::Owned);
850-
}
810+
// Look through parens here; other than parens, specifiers
811+
// must appear at the top level of a parameter type.
812+
while (auto *tupleRepr = dyn_cast<TupleTypeRepr>(nestedRepr)) {
813+
if (!tupleRepr->isParenType())
814+
break;
815+
nestedRepr = tupleRepr->getElementType(0);
816+
}
817+
818+
if (isa<InOutTypeRepr>(nestedRepr)) {
819+
param->setSpecifier(ParamDecl::Specifier::InOut);
820+
} else if (isa<SharedTypeRepr>(nestedRepr)) {
821+
param->setSpecifier(ParamDecl::Specifier::Shared);
822+
} else if (isa<OwnedTypeRepr>(nestedRepr)) {
823+
param->setSpecifier(ParamDecl::Specifier::Owned);
851824
}
852825

853-
if (param->isInOut() && param->isDefaultArgument()) {
826+
if (isa<InOutTypeRepr>(nestedRepr) &&
827+
param->isDefaultArgument()) {
854828
diagnose(param->getDefaultValue()->getLoc(),
855829
swift::diag::cannot_provide_default_value_inout,
856830
param->getName());
857-
param->markInvalid();
858-
hadError = true;
831+
param->setSpecifier(ParamDecl::Specifier::Default);
859832
}
860833
}
861834

trunk/test/IDE/complete_default_arguments.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
//
2020
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=DEFAULT_ARG_INIT_1 | %FileCheck %s -check-prefix=DEFAULT_ARG_INIT
2121
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=DEFAULT_ARG_INIT_2 | %FileCheck %s -check-prefix=DEFAULT_ARG_INIT_INTCONTEXT
22-
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=DEFAULT_ARG_INIT_3 | %FileCheck %s -check-prefix=DEFAULT_ARG_INIT
22+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=DEFAULT_ARG_INIT_3 | %FileCheck %s -check-prefix=DEFAULT_ARG_INIT_INTCONTEXT
2323
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=DEFAULT_ARG_INIT_4 | %FileCheck %s -check-prefix=DEFAULT_ARG_INIT_INTCONTEXT
2424

2525
func freeFuncWithDefaultArgs1(

trunk/test/decl/func/default-values.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,14 @@ func inoutFuncWithDefaultArg1(x: inout Int = 1) {} // expected-error {{cannot pr
132132
func inoutFuncWithDefaultArg2(x: inout Int = bLiteral) {} // expected-error {{cannot provide default value to inout parameter 'x'}}
133133
func inoutFuncWithDefaultArg3(x: inout Int = aLiteral) {} // expected-error {{cannot provide default value to inout parameter 'x'}}
134134
func inoutFuncWithDefaultArg4(x: inout Int = &aLiteral) {} // expected-error {{cannot provide default value to inout parameter 'x'}}
135+
// expected-error@-1 {{use of extraneous '&'}}
136+
135137
func inoutFuncWithDefaultArg5(x: inout Int = &bLiteral) {} // expected-error {{cannot provide default value to inout parameter 'x'}}
138+
// expected-error@-1 {{use of extraneous '&'}}
139+
136140
func inoutFuncWithDefaultArg6(x: inout Int = #file) {} // expected-error {{cannot provide default value to inout parameter 'x'}}
141+
// expected-error@-1 {{default argument value of type 'String' cannot be converted to type 'Int'}}
142+
137143
func inoutFuncWithDefaultArg7(_: inout Int = 1) {} // expected-error {{cannot provide default value to inout parameter '_'}}
138144

139145
// SE-0242 - Test that memberwise constructor generates default values

trunk/test/expr/expressions.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,7 @@ func inoutTests(_ arr: inout Int) {
851851
// <rdar://problem/20802757> Compiler crash in default argument & inout expr
852852
var g20802757 = 2
853853
func r20802757(_ z: inout Int = &g20802757) { // expected-error {{cannot provide default value to inout parameter 'z'}}
854+
// expected-error@-1 {{use of extraneous '&'}}
854855
print(z)
855856
}
856857

trunk/validation-test/compiler_crashers_fixed/28723-unreachable-executed-at-swift-lib-sema-csdiag-cpp-4012.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// See https://swift.org/LICENSE.txt for license information
66
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
77

8+
// rdar://56144412
9+
// XFAIL: *
810
// RUN: not %target-swift-frontend %s -emit-ir
911
func t(UInt=__FUNCTION__
1012
func&t(

0 commit comments

Comments
 (0)