diff --git a/lib/ASTGen/Sources/ASTGen/Diagnostics.swift b/lib/ASTGen/Sources/ASTGen/Diagnostics.swift index cc5b6285d2d27..9c9fa54a563b5 100644 --- a/lib/ASTGen/Sources/ASTGen/Diagnostics.swift +++ b/lib/ASTGen/Sources/ASTGen/Diagnostics.swift @@ -89,6 +89,7 @@ func emitDiagnostic( diagEnginePtr: UnsafeMutablePointer, sourceFileBuffer: UnsafeMutableBufferPointer, diagnostic: Diagnostic, + diagnosticSeverity: DiagnosticSeverity, messageSuffix: String? = nil ) { // Emit the main diagnostic @@ -96,7 +97,7 @@ func emitDiagnostic( diagEnginePtr: diagEnginePtr, sourceFileBuffer: sourceFileBuffer, message: diagnostic.diagMessage.message + (messageSuffix ?? ""), - severity: diagnostic.diagMessage.severity, + severity: diagnosticSeverity, position: diagnostic.position, highlights: diagnostic.highlights ) @@ -107,7 +108,8 @@ func emitDiagnostic( diagEnginePtr: diagEnginePtr, sourceFileBuffer: sourceFileBuffer, message: fixIt.message.message, - severity: .note, position: diagnostic.position, + severity: .note, + position: diagnostic.position, fixItChanges: fixIt.changes.changes ) } @@ -118,7 +120,8 @@ func emitDiagnostic( diagEnginePtr: diagEnginePtr, sourceFileBuffer: sourceFileBuffer, message: note.message, - severity: .note, position: note.position + severity: .note, + position: note.position ) } } diff --git a/lib/ASTGen/Sources/ASTGen/SourceFile.swift b/lib/ASTGen/Sources/ASTGen/SourceFile.swift index f394fa57aa403..5def6146f4a6a 100644 --- a/lib/ASTGen/Sources/ASTGen/SourceFile.swift +++ b/lib/ASTGen/Sources/ASTGen/SourceFile.swift @@ -1,3 +1,4 @@ +import SwiftDiagnostics import SwiftParser import SwiftSyntax import SwiftParserDiagnostics @@ -77,7 +78,8 @@ extension Syntax { public func emitParserDiagnostics( diagEnginePtr: UnsafeMutablePointer, sourceFilePtr: UnsafeMutablePointer, - emitOnlyErrors: CInt + emitOnlyErrors: CInt, + downgradePlaceholderErrorsToWarnings: CInt ) -> CInt { return sourceFilePtr.withMemoryRebound( to: ExportedSourceFile.self, capacity: 1 @@ -94,7 +96,15 @@ public func emitParserDiagnostics( if diag.node.isInIfConfig { continue } - if emitOnlyErrors != 0, diag.diagMessage.severity != .error { + + let diagnosticSeverity: DiagnosticSeverity + if downgradePlaceholderErrorsToWarnings == 1 && diag.diagMessage.diagnosticID == StaticTokenError.editorPlaceholder.diagnosticID { + diagnosticSeverity = .warning + } else { + diagnosticSeverity = diag.diagMessage.severity + } + + if emitOnlyErrors != 0, diagnosticSeverity != .error { continue } @@ -102,7 +112,8 @@ public func emitParserDiagnostics( diagEnginePtr: diagEnginePtr, sourceFileBuffer: UnsafeMutableBufferPointer( mutating: sourceFile.pointee.buffer), - diagnostic: diag + diagnostic: diag, + diagnosticSeverity: diagnosticSeverity ) anyDiags = true } diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index 538cca77fb0fe..32b2c2f6bbc9a 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -186,9 +186,10 @@ extern "C" int swift_ASTGen_roundTripCheck(void *sourceFile); /// Emit parser diagnostics for given source file.. Returns non-zero if any /// diagnostics were emitted. -extern "C" int swift_ASTGen_emitParserDiagnostics(void *diagEngine, - void *sourceFile, - int emitOnlyErrors); +extern "C" int +swift_ASTGen_emitParserDiagnostics(void *diagEngine, void *sourceFile, + int emitOnlyErrors, + int downgradePlaceholderErrorsToWarnings); // Build AST nodes for the top-level entities in the syntax. extern "C" void swift_ASTGen_buildTopLevelASTNodes(void *sourceFile, @@ -274,9 +275,12 @@ void Parser::parseTopLevelItems(SmallVectorImpl &items) { diagnose(loc, diag::parser_round_trip_error); } else if (Context.LangOpts.hasFeature(Feature::ParserValidation) && !Context.Diags.hadAnyError() && - swift_ASTGen_emitParserDiagnostics(&Context.Diags, - SF.exportedSourceFile, - /*emitOnlyErrors=*/true)) { + swift_ASTGen_emitParserDiagnostics( + &Context.Diags, SF.exportedSourceFile, + /*emitOnlyErrors=*/true, + /*downgradePlaceholderErrorsToWarnings=*/ + Context.LangOpts.Playground || + Context.LangOpts.WarnOnEditorPlaceholder)) { // We might have emitted warnings in the C++ parser but no errors, in // which case we still have `hadAnyError() == false`. To avoid emitting // the same warnings from SwiftParser, only emit errors from SwiftParser @@ -316,7 +320,10 @@ Parser::parseSourceFileViaASTGen(SmallVectorImpl &items, Context.LangOpts.hasFeature(Feature::ParserASTGen)) && !suppressDiagnostics && swift_ASTGen_emitParserDiagnostics( - &Context.Diags, SF.exportedSourceFile, /*emitOnlyErrors=*/false) && + &Context.Diags, SF.exportedSourceFile, /*emitOnlyErrors=*/false, + /*downgradePlaceholderErrorsToWarnings=*/ + Context.LangOpts.Playground || + Context.LangOpts.WarnOnEditorPlaceholder) && Context.Diags.hadAnyError() && !Context.LangOpts.hasFeature(Feature::ParserASTGen)) { // Errors were emitted, and we're still using the C++ parser, so