@@ -186,9 +186,9 @@ extern "C" int swift_ASTGen_roundTripCheck(void *sourceFile);
186
186
187
187
// / Emit parser diagnostics for given source file.. Returns non-zero if any
188
188
// / 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 );
192
192
193
193
// Build AST nodes for the top-level entities in the syntax.
194
194
extern " C" void swift_ASTGen_buildTopLevelASTNodes (void *sourceFile,
@@ -274,8 +274,12 @@ void Parser::parseTopLevelItems(SmallVectorImpl<ASTNode> &items) {
274
274
diagnose (loc, diag::parser_round_trip_error);
275
275
} else if (Context.LangOpts .hasFeature (Feature::ParserValidation) &&
276
276
!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
279
283
SourceLoc loc;
280
284
if (auto bufferID = SF.getBufferID ()) {
281
285
loc = Context.SourceMgr .getLocForBufferStart (*bufferID);
@@ -318,7 +322,7 @@ Parser::parseSourceFileViaASTGen(SmallVectorImpl<ASTNode> &items,
318
322
Context.LangOpts .hasFeature (Feature::ParserASTGen)) &&
319
323
!suppressDiagnostics &&
320
324
swift_ASTGen_emitParserDiagnostics (
321
- &Context.Diags , SF.exportedSourceFile ) &&
325
+ &Context.Diags , SF.exportedSourceFile , /* emitOnlyErrors= */ false ) &&
322
326
Context.Diags .hadAnyError () &&
323
327
!Context.LangOpts .hasFeature (Feature::ParserASTGen)) {
324
328
// Errors were emitted, and we're still using the C++ parser, so
0 commit comments