Skip to content

Commit 41c9af8

Browse files
committed
Downgrade placeholder error to warning for swiftparser
1 parent 7fd2f52 commit 41c9af8

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
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: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ extern "C" int swift_ASTGen_roundTripCheck(void *sourceFile);
188188
/// diagnostics were emitted.
189189
extern "C" int swift_ASTGen_emitParserDiagnostics(void *diagEngine,
190190
void *sourceFile,
191-
int emitOnlyErrors);
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,
@@ -276,7 +277,8 @@ void Parser::parseTopLevelItems(SmallVectorImpl<ASTNode> &items) {
276277
!Context.Diags.hadAnyError() &&
277278
swift_ASTGen_emitParserDiagnostics(&Context.Diags,
278279
SF.exportedSourceFile,
279-
/*emitOnlyErrors=*/true)) {
280+
/*emitOnlyErrors=*/true,
281+
/*downgradePlaceholderErrorsToWarnings=*/Context.LangOpts.WarnOnEditorPlaceholder)) {
280282
// We might have emitted warnings in the C++ parser but no errors, in
281283
// which case we still have `hadAnyError() == false`. To avoid emitting
282284
// the same warnings from SwiftParser, only emit errors from SwiftParser
@@ -316,7 +318,7 @@ Parser::parseSourceFileViaASTGen(SmallVectorImpl<ASTNode> &items,
316318
Context.LangOpts.hasFeature(Feature::ParserASTGen)) &&
317319
!suppressDiagnostics &&
318320
swift_ASTGen_emitParserDiagnostics(
319-
&Context.Diags, SF.exportedSourceFile, /*emitOnlyErrors=*/false) &&
321+
&Context.Diags, SF.exportedSourceFile, /*emitOnlyErrors=*/false, /*downgradePlaceholderErrorsToWarnings=*/Context.LangOpts.WarnOnEditorPlaceholder) &&
320322
Context.Diags.hadAnyError() &&
321323
!Context.LangOpts.hasFeature(Feature::ParserASTGen)) {
322324
// Errors were emitted, and we're still using the C++ parser, so

0 commit comments

Comments
 (0)