@@ -186,9 +186,9 @@ extern "C" int swift_ASTGen_roundTripCheck(void *sourceFile);
186186
187187// / Emit parser diagnostics for given source file.. Returns non-zero if any
188188// / diagnostics were emitted.
189- extern " C" int swift_ASTGen_emitParserDiagnostics (
190- void *diagEngine, void *sourceFile
191- );
189+ extern " C" int swift_ASTGen_emitParserDiagnostics (void *diagEngine,
190+ void *sourceFile,
191+ int emitOnlyErrors );
192192
193193// Build AST nodes for the top-level entities in the syntax.
194194extern " C" void swift_ASTGen_buildTopLevelASTNodes (void *sourceFile,
@@ -274,8 +274,12 @@ void Parser::parseTopLevelItems(SmallVectorImpl<ASTNode> &items) {
274274 diagnose (loc, diag::parser_round_trip_error);
275275 } else if (Context.LangOpts .hasFeature (Feature::ParserValidation) &&
276276 !Context.Diags .hadAnyError () &&
277- swift_ASTGen_emitParserDiagnostics (
278- &Context.Diags , SF.exportedSourceFile )) {
277+ swift_ASTGen_emitParserDiagnostics (&Context.Diags ,
278+ SF.exportedSourceFile ,
279+ /* emitOnlyErrors=*/ true )) {
280+ // We might have emitted warnings in the C++ parser but no errors, in
281+ // which case we still have `hadAnyError() == false`. To avoid emitting
282+ // the same warnings from SwiftParser, only emit errors from SwiftParser
279283 SourceLoc loc;
280284 if (auto bufferID = SF.getBufferID ()) {
281285 loc = Context.SourceMgr .getLocForBufferStart (*bufferID);
@@ -318,7 +322,7 @@ Parser::parseSourceFileViaASTGen(SmallVectorImpl<ASTNode> &items,
318322 Context.LangOpts .hasFeature (Feature::ParserASTGen)) &&
319323 !suppressDiagnostics &&
320324 swift_ASTGen_emitParserDiagnostics (
321- &Context.Diags , SF.exportedSourceFile ) &&
325+ &Context.Diags , SF.exportedSourceFile , /* emitOnlyErrors= */ false ) &&
322326 Context.Diags .hadAnyError () &&
323327 !Context.LangOpts .hasFeature (Feature::ParserASTGen)) {
324328 // Errors were emitted, and we're still using the C++ parser, so
0 commit comments