diff --git a/lib/Sema/TypeCheckMacros.cpp b/lib/Sema/TypeCheckMacros.cpp index 7e22cfee5d11e..4428cf052f4ae 100644 --- a/lib/Sema/TypeCheckMacros.cpp +++ b/lib/Sema/TypeCheckMacros.cpp @@ -136,7 +136,7 @@ MacroDefinition MacroDefinitionRequest::evaluate( SM.getEntireTextForBuffer(sourceFile->getBufferID()); StringRef macroDeclText = SM.extractText(Lexer::getCharSourceRangeFromSourceRange( - SM, macro->getSourceRangeIncludingAttrs())); + SM, macro->getSourceRange())); auto checkResult = swift_Macros_checkMacroDefinition( &ctx.Diags, sourceFileText, macroDeclText, &externalMacroName, diff --git a/test/Macros/macros_diagnostics.swift b/test/Macros/macros_diagnostics.swift index 22bc34aed6c8c..60af15973b76c 100644 --- a/test/Macros/macros_diagnostics.swift +++ b/test/Macros/macros_diagnostics.swift @@ -234,3 +234,10 @@ func someGlobalNext( ) async throws { fatalError() } + +// This is testing if the definition is actually checked. The error means the '#externalMacro' was correctly parsed and checked. +#if true +@available(*, unavailable) +#endif +@freestanding(expression) public macro MacroWithIfConfigAttr() = #externalMacro(module: "ThisMacroModuleDoesNotExist", type: "ThisMacroTypeDoesNotExist") +// expected-warning@-1{{external macro implementation type 'ThisMacroModuleDoesNotExist.ThisMacroTypeDoesNotExist'}}