Skip to content

Commit 62b7a6f

Browse files
authored
Merge pull request #81346 from rintaro/macros-definition-typecheck-ifconfig
[Macros] Don't include attr range when checking macro definition
2 parents f298bde + 8519e71 commit 62b7a6f

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/Sema/TypeCheckMacros.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ MacroDefinition MacroDefinitionRequest::evaluate(
136136
SM.getEntireTextForBuffer(sourceFile->getBufferID());
137137
StringRef macroDeclText =
138138
SM.extractText(Lexer::getCharSourceRangeFromSourceRange(
139-
SM, macro->getSourceRangeIncludingAttrs()));
139+
SM, macro->getSourceRange()));
140140

141141
auto checkResult = swift_Macros_checkMacroDefinition(
142142
&ctx.Diags, sourceFileText, macroDeclText, &externalMacroName,

test/Macros/macros_diagnostics.swift

+7
Original file line numberDiff line numberDiff line change
@@ -234,3 +234,10 @@ func someGlobalNext(
234234
) async throws {
235235
fatalError()
236236
}
237+
238+
// This is testing if the definition is actually checked. The error means the '#externalMacro' was correctly parsed and checked.
239+
#if true
240+
@available(*, unavailable)
241+
#endif
242+
@freestanding(expression) public macro MacroWithIfConfigAttr() = #externalMacro(module: "ThisMacroModuleDoesNotExist", type: "ThisMacroTypeDoesNotExist")
243+
// expected-warning@-1{{external macro implementation type 'ThisMacroModuleDoesNotExist.ThisMacroTypeDoesNotExist'}}

0 commit comments

Comments
 (0)