Skip to content

Commit 8fb787d

Browse files
committed
Downgrade placeholder error to warning for swiftparser
1 parent df35da4 commit 8fb787d

File tree

3 files changed

+34
-13
lines changed

3 files changed

+34
-13
lines changed

lib/ASTGen/Sources/ASTGen/Diagnostics.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,15 @@ func emitDiagnostic(
8989
diagEnginePtr: UnsafeMutablePointer<UInt8>,
9090
sourceFileBuffer: UnsafeMutableBufferPointer<UInt8>,
9191
diagnostic: Diagnostic,
92+
diagnosticSeverity: DiagnosticSeverity,
9293
messageSuffix: String? = nil
9394
) {
9495
// Emit the main diagnostic
9596
emitDiagnosticParts(
9697
diagEnginePtr: diagEnginePtr,
9798
sourceFileBuffer: sourceFileBuffer,
9899
message: diagnostic.diagMessage.message + (messageSuffix ?? ""),
99-
severity: diagnostic.diagMessage.severity,
100+
severity: diagnosticSeverity,
100101
position: diagnostic.position,
101102
highlights: diagnostic.highlights
102103
)
@@ -107,7 +108,8 @@ func emitDiagnostic(
107108
diagEnginePtr: diagEnginePtr,
108109
sourceFileBuffer: sourceFileBuffer,
109110
message: fixIt.message.message,
110-
severity: .note, position: diagnostic.position,
111+
severity: .note,
112+
position: diagnostic.position,
111113
fixItChanges: fixIt.changes.changes
112114
)
113115
}
@@ -118,7 +120,8 @@ func emitDiagnostic(
118120
diagEnginePtr: diagEnginePtr,
119121
sourceFileBuffer: sourceFileBuffer,
120122
message: note.message,
121-
severity: .note, position: note.position
123+
severity: .note,
124+
position: note.position
122125
)
123126
}
124127
}

lib/ASTGen/Sources/ASTGen/SourceFile.swift

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import SwiftDiagnostics
12
import SwiftParser
23
import SwiftSyntax
34
import SwiftParserDiagnostics
@@ -77,7 +78,8 @@ extension Syntax {
7778
public func emitParserDiagnostics(
7879
diagEnginePtr: UnsafeMutablePointer<UInt8>,
7980
sourceFilePtr: UnsafeMutablePointer<UInt8>,
80-
emitOnlyErrors: CInt
81+
emitOnlyErrors: CInt,
82+
downgradePlaceholderErrorsToWarnings: CInt
8183
) -> CInt {
8284
return sourceFilePtr.withMemoryRebound(
8385
to: ExportedSourceFile.self, capacity: 1
@@ -94,15 +96,24 @@ public func emitParserDiagnostics(
9496
if diag.node.isInIfConfig {
9597
continue
9698
}
97-
if emitOnlyErrors != 0, diag.diagMessage.severity != .error {
99+
100+
let diagnosticSeverity: DiagnosticSeverity
101+
if downgradePlaceholderErrorsToWarnings == 1 && diag.diagMessage.diagnosticID == StaticTokenError.editorPlaceholder.diagnosticID {
102+
diagnosticSeverity = .warning
103+
} else {
104+
diagnosticSeverity = diag.diagMessage.severity
105+
}
106+
107+
if emitOnlyErrors != 0, diagnosticSeverity != .error {
98108
continue
99109
}
100110

101111
emitDiagnostic(
102112
diagEnginePtr: diagEnginePtr,
103113
sourceFileBuffer: UnsafeMutableBufferPointer(
104114
mutating: sourceFile.pointee.buffer),
105-
diagnostic: diag
115+
diagnostic: diag,
116+
diagnosticSeverity: diagnosticSeverity
106117
)
107118
anyDiags = true
108119
}

lib/Parse/ParseDecl.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,10 @@ 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(void *diagEngine,
190-
void *sourceFile,
191-
int emitOnlyErrors);
189+
extern "C" int
190+
swift_ASTGen_emitParserDiagnostics(void *diagEngine, void *sourceFile,
191+
int emitOnlyErrors,
192+
int downgradePlaceholderErrorsToWarnings);
192193

193194
// Build AST nodes for the top-level entities in the syntax.
194195
extern "C" void swift_ASTGen_buildTopLevelASTNodes(void *sourceFile,
@@ -274,9 +275,12 @@ void Parser::parseTopLevelItems(SmallVectorImpl<ASTNode> &items) {
274275
diagnose(loc, diag::parser_round_trip_error);
275276
} else if (Context.LangOpts.hasFeature(Feature::ParserValidation) &&
276277
!Context.Diags.hadAnyError() &&
277-
swift_ASTGen_emitParserDiagnostics(&Context.Diags,
278-
SF.exportedSourceFile,
279-
/*emitOnlyErrors=*/true)) {
278+
swift_ASTGen_emitParserDiagnostics(
279+
&Context.Diags, SF.exportedSourceFile,
280+
/*emitOnlyErrors=*/true,
281+
/*downgradePlaceholderErrorsToWarnings=*/
282+
Context.LangOpts.Playground ||
283+
Context.LangOpts.WarnOnEditorPlaceholder)) {
280284
// We might have emitted warnings in the C++ parser but no errors, in
281285
// which case we still have `hadAnyError() == false`. To avoid emitting
282286
// the same warnings from SwiftParser, only emit errors from SwiftParser
@@ -316,7 +320,10 @@ Parser::parseSourceFileViaASTGen(SmallVectorImpl<ASTNode> &items,
316320
Context.LangOpts.hasFeature(Feature::ParserASTGen)) &&
317321
!suppressDiagnostics &&
318322
swift_ASTGen_emitParserDiagnostics(
319-
&Context.Diags, SF.exportedSourceFile, /*emitOnlyErrors=*/false) &&
323+
&Context.Diags, SF.exportedSourceFile, /*emitOnlyErrors=*/false,
324+
/*downgradePlaceholderErrorsToWarnings=*/
325+
Context.LangOpts.Playground ||
326+
Context.LangOpts.WarnOnEditorPlaceholder) &&
320327
Context.Diags.hadAnyError() &&
321328
!Context.LangOpts.hasFeature(Feature::ParserASTGen)) {
322329
// Errors were emitted, and we're still using the C++ parser, so

0 commit comments

Comments
 (0)