Skip to content

Commit 115497e

Browse files
committed
---
yaml --- r: 341519 b: refs/heads/rxwei-patch-1 c: c86017e h: refs/heads/master i: 341517: 44c865a 341515: 15b2189 341511: 840f353 341503: efde5ca
1 parent 67a4bc6 commit 115497e

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2018-08-18-a: b10b1fce14385faa6d44f6b933e95
10151015
refs/heads/rdar-43033749-fix-batch-mode-no-diags-swift-5.0-branch: a14e64eaad30de89f0f5f0b2a782eed7ecdcb255
10161016
refs/heads/revert-19006-error-bridging-integer-type: 8a9065a3696535305ea53fe9b71f91cbe6702019
10171017
refs/heads/revert-19050-revert-19006-error-bridging-integer-type: ecf752d54b05dd0a20f510f0bfa54a3fec3bcaca
1018-
refs/heads/rxwei-patch-1: dd0f86a1ab4b83d98ad0f43473701ba9dad48cee
1018+
refs/heads/rxwei-patch-1: c86017e2988bd739240bbc255db88366a867ff30
10191019
refs/heads/shahmishal-patch-1: e58ec0f7488258d42bef51bc3e6d7b3dc74d7b2a
10201020
refs/heads/typelist-existential: 4046359efd541fb5c72d69a92eefc0a784df8f5e
10211021
refs/tags/swift-4.2-DEVELOPMENT-SNAPSHOT-2018-08-20-a: 4319ba09e4fb8650ee86061075c74a016b6baab9

branches/rxwei-patch-1/include/swift/AST/DiagnosticsParse.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,8 @@ ERROR(expected_rbracket_dictionary_type,PointsToFirstBadToken,
758758
"expected ']' in dictionary type", ())
759759
ERROR(extra_rbracket,PointsToFirstBadToken,
760760
"unexpected ']' in type; did you mean to write an array type?", ())
761+
ERROR(extra_colon,PointsToFirstBadToken,
762+
"unexpected ':' in type; did you mean to write a dictionary type?", ())
761763

762764
// Tuple Types
763765
ERROR(expected_rparen_tuple_type_list,none,

branches/rxwei-patch-1/lib/Parse/ParseType.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,11 +523,25 @@ ParserResult<TypeRepr> Parser::parseDeclResultType(Diag<> MessageID) {
523523

524524
auto result = parseType(MessageID);
525525

526-
if (result.isNonNull() && Tok.is(tok::r_square)) {
526+
if (!result.isParseError() && Tok.is(tok::r_square)) {
527527
auto diag = diagnose(Tok, diag::extra_rbracket);
528528
diag.fixItInsert(result.get()->getStartLoc(), getTokenText(tok::l_square));
529529
consumeToken();
530530
return makeParserErrorResult(new (Context) ErrorTypeRepr(Tok.getLoc()));
531+
} else if (!result.isParseError() && Tok.is(tok::colon)) {
532+
auto colonTok = consumeToken();
533+
auto secondType = parseType(diag::expected_dictionary_value_type);
534+
535+
auto diag = diagnose(colonTok, diag::extra_colon);
536+
diag.fixItInsert(result.get()->getStartLoc(), getTokenText(tok::l_square));
537+
if (!secondType.isParseError()) {
538+
if (Tok.is(tok::r_square)) {
539+
consumeToken();
540+
} else {
541+
diag.fixItInsertAfter(secondType.get()->getEndLoc(), getTokenText(tok::r_square));
542+
}
543+
}
544+
return makeParserErrorResult(new (Context) ErrorTypeRepr(Tok.getLoc()));
531545
}
532546
return result;
533547
}

branches/rxwei-patch-1/test/Parse/recovery.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,14 @@ struct ErrorTypeInVarDeclArrayType5 { // expected-note {{in declaration of 'Erro
470470
let a7: [String: Int]] // expected-error {{unexpected ']' in type; did you mean to write an array type?}} {{11-11=[}}
471471
}
472472

473+
struct ErrorTypeInVarDeclDictionaryType {
474+
let a1: String: // expected-error {{unexpected ':' in type; did you mean to write a dictionary type?}} {{11-11=[}}
475+
// expected-error @-1 {{expected dictionary value type}}
476+
let a2: String: Int] // expected-error {{unexpected ':' in type; did you mean to write a dictionary type?}} {{11-11=[}}
477+
let a3: String: [Int] // expected-error {{unexpected ':' in type; did you mean to write a dictionary type?}} {{11-11=[}} {{24-24=]}}
478+
let a4: String: Int // expected-error {{unexpected ':' in type; did you mean to write a dictionary type?}} {{11-11=[}} {{22-22=]}}
479+
}
480+
473481
struct ErrorInFunctionSignatureResultArrayType1 {
474482
func foo() -> Int[ { // expected-error {{expected '{' in body of function declaration}}
475483
return [0]

0 commit comments

Comments
 (0)