Skip to content

Commit bd17b06

Browse files
authored
Merge pull request #71528 from tshortli/fallback-conformance-diagnostic-crash
AST: Avoid crash when emitting a conformance diagnostic without a source file
2 parents 5b0d9c4 + 5228b8b commit bd17b06

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/AST/ASTContext.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2902,14 +2902,19 @@ static void maybeEmitFallbackConformanceDiagnostic(
29022902
if (diagnostics.HadError)
29032903
return;
29042904

2905-
diagnostics.HadError = true;
2906-
29072905
auto *proto = conformance->getProtocol();
29082906
auto *dc = conformance->getDeclContext();
29092907
auto *sf = dc->getParentSourceFile();
2908+
2909+
// FIXME: There should probably still be a diagnostic even without a file.
2910+
if (!sf)
2911+
return;
2912+
29102913
auto *mod = sf->getParentModule();
29112914
assert(mod->isMainModule());
29122915

2916+
diagnostics.HadError = true;
2917+
29132918
// If we have at least one primary file and the conformance is declared in a
29142919
// non-primary file, emit a fallback diagnostic.
29152920
if ((!sf->isPrimary() && !mod->getPrimarySourceFiles().empty()) ||

0 commit comments

Comments
 (0)