Skip to content

Commit bbed527

Browse files
authored
Merge pull request #27862 from CodaFi/valid-the-impalers-revenge
Remove The Last Vestiges of `isInvalid` from Parse Harder This Time
2 parents dfe00c3 + a772d76 commit bbed527

File tree

9 files changed

+20
-43
lines changed

9 files changed

+20
-43
lines changed

include/swift/AST/DiagnosticsParse.def

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -870,8 +870,6 @@ ERROR(expected_parameter_colon,PointsToFirstBadToken,
870870
"expected ':' following argument label and parameter name", ())
871871
ERROR(expected_assignment_instead_of_comparison_operator,none,
872872
"expected '=' instead of '==' to assign default value for parameter", ())
873-
ERROR(missing_parameter_type,PointsToFirstBadToken,
874-
"parameter requires an explicit type", ())
875873
ERROR(multiple_parameter_ellipsis,none,
876874
"only a single variadic parameter '...' is permitted", ())
877875
ERROR(parameter_vararg_default,none,

lib/Parse/ParseDecl.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4933,12 +4933,6 @@ void Parser::ParsedAccessors::record(Parser &P, AbstractStorageDecl *storage,
49334933
storage->setAccessors(LBLoc, Accessors, RBLoc);
49344934
}
49354935

4936-
static void flagInvalidAccessor(AccessorDecl *func) {
4937-
if (func) {
4938-
func->setInvalid();
4939-
}
4940-
}
4941-
49424936
static void diagnoseConflictingAccessors(Parser &P, AccessorDecl *first,
49434937
AccessorDecl *&second) {
49444938
if (!second) return;
@@ -4949,7 +4943,7 @@ static void diagnoseConflictingAccessors(Parser &P, AccessorDecl *first,
49494943
P.diagnose(first->getLoc(), diag::previous_accessor,
49504944
getAccessorNameForDiagnostic(first, /*article*/ false),
49514945
/*already*/ false);
4952-
flagInvalidAccessor(second);
4946+
second->setInvalid();
49534947
}
49544948

49554949
template <class... DiagArgs>
@@ -4959,11 +4953,11 @@ static void diagnoseAndIgnoreObservers(Parser &P,
49594953
typename std::enable_if<true, DiagArgs>::type... args) {
49604954
if (auto &accessor = accessors.WillSet) {
49614955
P.diagnose(accessor->getLoc(), diagnostic, /*willSet*/ 0, args...);
4962-
flagInvalidAccessor(accessor);
4956+
accessor->setInvalid();
49634957
}
49644958
if (auto &accessor = accessors.DidSet) {
49654959
P.diagnose(accessor->getLoc(), diagnostic, /*didSet*/ 1, args...);
4966-
flagInvalidAccessor(accessor);
4960+
accessor->setInvalid();
49674961
}
49684962
}
49694963

@@ -4975,7 +4969,7 @@ void Parser::ParsedAccessors::classify(Parser &P, AbstractStorageDecl *storage,
49754969
// was invalid.
49764970
if (invalid) {
49774971
for (auto accessor : Accessors) {
4978-
flagInvalidAccessor(accessor);
4972+
accessor->setInvalid();
49794973
}
49804974
}
49814975

lib/Parse/ParseExpr.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2656,11 +2656,10 @@ parseClosureSignatureIfPresent(SmallVectorImpl<CaptureListEntry> &captureList,
26562656
// to detect any tuple splat or destructuring as early as
26572657
// possible and give a proper fix-it. See SE-0110 for more details.
26582658
auto isTupleDestructuring = [](ParamDecl *param) -> bool {
2659-
if (!param->isInvalid())
2659+
auto *typeRepr = param->getTypeRepr();
2660+
if (!(typeRepr && typeRepr->isInvalid()))
26602661
return false;
2661-
if (auto *typeRepr = param->getTypeRepr())
2662-
return !param->hasName() && isa<TupleTypeRepr>(typeRepr);
2663-
return false;
2662+
return !param->hasName() && isa<TupleTypeRepr>(typeRepr);
26642663
};
26652664

26662665
for (unsigned i = 0, e = params->size(); i != e; ++i) {

lib/Parse/ParsePattern.cpp

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,9 @@ Parser::parseParameterClause(SourceLoc &leftParenLoc,
327327
// was invalid. Remember that.
328328
if (type.isParseError() && !type.hasCodeCompletion())
329329
param.isInvalid = true;
330+
} else if (paramContext != Parser::ParameterContextKind::Closure) {
331+
diagnose(Tok, diag::expected_parameter_colon);
332+
param.isInvalid = true;
330333
}
331334
} else {
332335
// Otherwise, we have invalid code. Check to see if this looks like a
@@ -358,8 +361,9 @@ Parser::parseParameterClause(SourceLoc &leftParenLoc,
358361
// on is most likely argument destructuring, we are going
359362
// to diagnose that after all of the parameters are parsed.
360363
if (param.Type) {
361-
// Mark current parameter as invalid so it is possible
364+
// Mark current parameter type as invalid so it is possible
362365
// to diagnose it as destructuring of the closure parameter list.
366+
param.Type->setInvalid();
363367
param.isInvalid = true;
364368
if (!isClosure) {
365369
// Unnamed parameters must be written as "_: Type".
@@ -478,12 +482,6 @@ mapParsedParameters(Parser &parser,
478482
parser.CurDeclContext);
479483
param->getAttrs() = paramInfo.Attrs;
480484

481-
auto setInvalid = [&]{
482-
if (param->isInvalid())
483-
return;
484-
param->setInvalid();
485-
};
486-
487485
bool parsingEnumElt
488486
= (paramContext == Parser::ParameterContextKind::EnumElement);
489487
// If we're not parsing an enum case, lack of a SourceLoc for both
@@ -493,7 +491,7 @@ mapParsedParameters(Parser &parser,
493491

494492
// If we diagnosed this parameter as a parse error, propagate to the decl.
495493
if (paramInfo.isInvalid)
496-
setInvalid();
494+
param->setInvalid();
497495

498496
// If a type was provided, create the type for the parameter.
499497
if (auto type = paramInfo.Type) {
@@ -524,13 +522,6 @@ mapParsedParameters(Parser &parser,
524522
// or typealias with underlying function type.
525523
param->setAutoClosure(attrs.has(TypeAttrKind::TAK_autoclosure));
526524
}
527-
} else if (paramContext != Parser::ParameterContextKind::Closure) {
528-
// Non-closure parameters require a type.
529-
if (!param->isInvalid())
530-
parser.diagnose(param->getLoc(), diag::missing_parameter_type);
531-
532-
param->setSpecifier(ParamSpecifier::Default);
533-
setInvalid();
534525
} else if (paramInfo.SpecifierLoc.isValid()) {
535526
StringRef specifier;
536527
switch (paramInfo.SpecifierKind) {
@@ -708,7 +699,7 @@ Parser::parseSingleParameterClause(ParameterContextKind paramContext,
708699
// Parse the parameter clause.
709700
status |= parseParameterClause(leftParenLoc, params, rightParenLoc,
710701
defaultArgs, paramContext);
711-
702+
712703
// Turn the parameter clause into argument and body patterns.
713704
auto paramList = mapParsedParameters(*this, leftParenLoc, params,
714705
rightParenLoc, namePieces, paramContext);

test/Constraints/tuple_arguments.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,8 +1468,6 @@ let _ = sr4745.enumerated().map { (count, element) in "\(count): \(element)" }
14681468
// SR-4738
14691469

14701470
let sr4738 = (1, (2, 3))
1471-
// expected-error@+2{{use of undeclared type 'y'}}
1472-
// expected-error@+1{{use of undeclared type 'z'}}
14731471
[sr4738].map { (x, (y, z)) -> Int in x + y + z }
14741472
// expected-error@-1 {{closure tuple parameter does not support destructuring}} {{20-26=arg1}} {{38-38=let (y, z) = arg1; }}
14751473

@@ -1478,10 +1476,8 @@ let r31892961_1 = [1: 1, 2: 2]
14781476
r31892961_1.forEach { (k, v) in print(k + v) }
14791477

14801478
let r31892961_2 = [1, 2, 3]
1481-
// expected-error@+1{{use of undeclared type 'val'}}
14821479
let _: [Int] = r31892961_2.enumerated().map { ((index, val)) in
14831480
// expected-error@-1 {{closure tuple parameter does not support destructuring}} {{48-60=arg0}} {{3-3=\n let (index, val) = arg0\n }}
1484-
// expected-error@-2 {{use of undeclared type 'index'}}
14851481
val + 1
14861482
}
14871483

@@ -1690,6 +1686,7 @@ class Mappable<T> {
16901686

16911687
let x = Mappable(())
16921688
_ = x.map { (_: Void) in return () }
1689+
_ = x.map { (_: ()) in () }
16931690

16941691
// https://bugs.swift.org/browse/SR-9470
16951692
do {
@@ -1756,3 +1753,4 @@ func noescapeSplat() {
17561753
takesEscaping(t.0)
17571754
}
17581755
}
1756+

test/IDE/complete_default_arguments.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
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
2222
// 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
23-
// 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
2423

2524
func freeFuncWithDefaultArgs1(
2625
_ a: Int, b: Int = 42, file: String = #file, line: Int = #line,
@@ -135,8 +134,7 @@ func testDefaultArgs9(_ x: C2) {
135134
let globalVar = 1
136135
func testDefaultArgInit1(x = #^DEFAULT_ARG_INIT_1^#) { }
137136
func testDefaultArgInit2(_: Int = #^DEFAULT_ARG_INIT_2^#) { }
138-
func testDefaultArgInit3(Int = #^DEFAULT_ARG_INIT_3^#) { }
139-
func testDefaultArgInit4(_ x: Int = #^DEFAULT_ARG_INIT_4^#) { }
137+
func testDefaultArgInit3(_ x: Int = #^DEFAULT_ARG_INIT_3^#) { }
140138
// DEFAULT_ARG_INIT: Begin completions
141139
// DEFAULT_ARG_INIT: Decl[GlobalVar]/CurrModule: globalVar[#Int#]{{; name=.+$}}
142140
// DEFAULT_ARG_INIT: End completions

test/Parse/invalid.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ protocol Animal<Food> { // expected-error {{protocols do not allow generic para
7676
// SR-573 - Crash with invalid parameter declaration
7777
class Starfish {}
7878
struct Salmon {}
79-
func f573(s Starfish, // expected-error {{parameter requires an explicit type}}
79+
func f573(s Starfish, // expected-error {{expected ':' following argument label and parameter name}}
8080
_ ss: Salmon) -> [Int] {}
8181
func g573() { f573(Starfish(), Salmon()) }
8282

@@ -89,7 +89,7 @@ func SR979b(inout inout b: Int) {} // expected-error {{inout' before a parameter
8989
// expected-error@-1 {{parameter must not have multiple '__owned', 'inout', or '__shared' specifiers}} {{19-25=}}
9090
func SR979d(let let a: Int) {} // expected-warning {{'let' in this position is interpreted as an argument label}} {{13-16=`let`}}
9191
// expected-error @-1 {{expected ',' separator}} {{20-20=,}}
92-
// expected-error @-2 {{parameter requires an explicit type}}
92+
// expected-error @-2 {{expected ':' following argument label and parameter name}}
9393
// expected-warning @-3 {{extraneous duplicate parameter name; 'let' already has an argument label}} {{13-17=}}
9494
func SR979e(inout x: inout String) {} // expected-error {{parameter must not have multiple '__owned', 'inout', or '__shared' specifiers}} {{13-18=}}
9595
func SR979g(inout i: inout Int) {} // expected-error {{parameter must not have multiple '__owned', 'inout', or '__shared' specifiers}} {{13-18=}}

test/Sema/immutability.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ func testSelectorStyleArguments1(_ x: Int, bar y: Int) {
370370
func testSelectorStyleArguments2(let x: Int, // expected-warning {{'let' in this position is interpreted as an argument label}}{{34-37=`let`}}
371371
let bar y: Int) { // expected-warning {{'let' in this position is interpreted as an argument label}}{{34-37=`let`}}
372372
// expected-error @-1 {{expected ',' separator}}
373-
// expected-error @-2 {{parameter requires an explicit type}}
373+
// expected-error @-2 {{expected ':' following argument label and parameter name}}
374374
}
375375
func testSelectorStyleArguments3(_ x: Int, bar y: Int) {
376376
++x // expected-error {{cannot pass immutable value to mutating operator: 'x' is a 'let' constant}}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
77

88
// rdar://56144412
9-
// XFAIL: asserts
109
// RUN: not %target-swift-frontend %s -emit-ir
1110
func t(UInt=__FUNCTION__
1211
func&t(

0 commit comments

Comments
 (0)