@@ -6663,27 +6663,55 @@ ParserResult<ImportDecl> Parser::parseDeclImport(ParseDeclOptions Flags,
66636663 }
66646664
66656665 ImportPath::Builder importPath;
6666- bool HasNext;
6667- do {
6668- if (Tok.is (tok::code_complete)) {
6669- consumeToken ();
6670- if (CodeCompletionCallbacks) {
6671- CodeCompletionCallbacks->completeImportDecl (importPath);
6672- }
6673- return makeParserCodeCompletionStatus ();
6666+ if (Kind != ImportKind::Module && isAtModuleSelector ()) {
6667+ // First, parse as much as possible.
6668+ importPath.push_back (*parseModuleSelector ());
6669+
6670+ Identifier declName;
6671+ SourceLoc declNameLoc;
6672+ if (Tok.isAtStartOfLine ()) {
6673+ diagnose (getEndOfPreviousLoc (),
6674+ diag::expected_identifier_after_module_selector);
6675+ } else {
6676+ parseAnyIdentifier (declName, declNameLoc,
6677+ diag::expected_identifier_after_module_selector,
6678+ /* diagnoseDollarPrefix=*/ true );
66746679 }
6675- importPath.push_back (Identifier (), Tok.getLoc ());
6676- if (parseAnyIdentifier (importPath.back ().Item ,
6677- /* diagnoseDollarPrefix=*/ false ,
6678- diag::expected_identifier_in_decl, " import" ))
6679- return nullptr ;
6680- if (Tok.is (tok::oper_postfix)) {
6680+ importPath.push_back (declName, declNameLoc);
6681+
6682+ // If either identifier failed to parse, bail.
6683+ for (auto &elem : importPath) {
6684+ if (elem.Item .empty ())
6685+ return nullptr ;
6686+ }
6687+ } else {
6688+ bool HasNext;
6689+ do {
6690+ if (Tok.is (tok::code_complete)) {
6691+ consumeToken ();
6692+ if (CodeCompletionCallbacks) {
6693+ CodeCompletionCallbacks->completeImportDecl (importPath);
6694+ }
6695+ return makeParserCodeCompletionStatus ();
6696+ }
6697+ importPath.push_back (Identifier (), Tok.getLoc ());
6698+ if (parseAnyIdentifier (importPath.back ().Item ,
6699+ /* diagnoseDollarPrefix=*/ false ,
6700+ diag::expected_identifier_in_decl, " import" ))
6701+ return nullptr ;
6702+ if (Tok.is (tok::oper_postfix)) {
66816703 diagnose (Tok, diag::unexpected_operator_in_import_path)
66826704 .fixItRemove (Tok.getLoc ());
66836705 return nullptr ;
6684- }
6685- HasNext = consumeIf (tok::period);
6686- } while (HasNext);
6706+ }
6707+ if (Tok.is (tok::colon_colon)) {
6708+ diagnose (Tok, diag::module_selector_submodule_not_allowed);
6709+ diagnose (Tok, diag::replace_module_selector_with_member_lookup)
6710+ .fixItReplace (Tok.getLoc (), " ." );
6711+ }
6712+ HasNext = consumeIf (tok::period) || consumeIf (tok::colon_colon);
6713+ } while (HasNext);
6714+ }
66876715
66886716 if (Tok.is (tok::code_complete)) {
66896717 // We omit the code completion token if it immediately follows the module
0 commit comments