Skip to content

Commit 0e3bdf7

Browse files
Merge pull request #79371 from cachemeifyoucan/eng/PR-144810862
[Caching] Fix a bug when emitting diagnostics from nested macros
2 parents e0359f7 + 0613fca commit 0e3bdf7

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

lib/Frontend/CachedDiagnostics.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ unsigned DiagnosticSerializer::getFileIDFromBufferID(SourceManager &SM,
348348

349349
Files.emplace_back(std::move(File));
350350
Allocated.insert({Idx, ++CurrentFileID});
351-
351+
unsigned NewFileID = CurrentFileID;
352352

353353
auto Info = SM.getGeneratedSourceInfo(Idx);
354354
auto convertGeneratedFileInfo =
@@ -364,7 +364,7 @@ unsigned DiagnosticSerializer::getFileIDFromBufferID(SourceManager &SM,
364364
GeneratedFileInfo.emplace_back(std::move(GI));
365365
}
366366

367-
return CurrentFileID;
367+
return NewFileID;
368368
}
369369

370370
SerializedSourceLoc

test/CAS/cached_diagnostics_macro.swift

+11
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,23 @@ public struct CallDeprecatedMacro: ExpressionMacro {
4949
}
5050
}
5151

52+
public struct ToMyWarningMacro: ExpressionMacro {
53+
public static func expansion(
54+
of macro: some FreestandingMacroExpansionSyntax,
55+
in context: some MacroExpansionContext
56+
) throws -> ExprSyntax {
57+
return "#myWarning(\"\")"
58+
}
59+
}
60+
5261
//--- main.swift
5362
@freestanding(expression) macro myWarning(_ message: String) = #externalMacro(module: "MacroDefinition", type: "CallDeprecatedMacro")
63+
@freestanding(expression) macro toMyWarning(_ message: String) = #externalMacro(module: "MacroDefinition", type: "ToMyWarningMacro")
5464

5565
@available(*, deprecated)
5666
func testDeprecated() {}
5767

5868
func testDiscardableStringify(x: Int) {
69+
#toMyWarning("this is a warning")
5970
#myWarning("this is a warning")
6071
}

0 commit comments

Comments
 (0)