Skip to content

[Macros] Don't include attr range when checking macro definition #81346

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Sema/TypeCheckMacros.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions test/Macros/macros_diagnostics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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'}}