Skip to content

Commit 3c80b71

Browse files
committed
[Macros] Fix end location of macro declarations with where clauses
1 parent 1a124e7 commit 3c80b71

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

lib/AST/Decl.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9665,7 +9665,10 @@ Type MacroDecl::getResultInterfaceType() const {
96659665
}
96669666

96679667
SourceRange MacroDecl::getSourceRange() const {
9668-
return SourceRange(macroLoc, externalMacroTypeNameLoc);
9668+
SourceLoc endLoc = externalMacroTypeNameLoc;
9669+
if (auto trailing = getTrailingWhereClause())
9670+
endLoc = trailing->getSourceRange().End;
9671+
return SourceRange(macroLoc, endLoc);
96699672
}
96709673

96719674
SourceRange MacroExpansionDecl::getSourceRange() const {

lib/Sema/TypeCheckType.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4880,6 +4880,9 @@ void TypeChecker::checkExistentialTypes(Decl *decl) {
48804880
checkExistentialTypes(ctx, funcDecl->getGenericParams());
48814881
checkExistentialTypes(ctx, funcDecl->getTrailingWhereClause());
48824882
}
4883+
} else if (auto *macroDecl = dyn_cast<MacroDecl>(decl)) {
4884+
checkExistentialTypes(ctx, macroDecl->getGenericParams());
4885+
checkExistentialTypes(ctx, macroDecl->getTrailingWhereClause());
48834886
}
48844887

48854888
if (isa<TypeDecl>(decl) || isa<ExtensionDecl>(decl))

test/Macros/builtin_macros.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %target-swift-frontend -enable-experimental-feature Macros -enable-experimental-feature BuiltinMacros -dump-ast %s -module-name MacrosTest 2>&1 | %FileCheck %s
22
// REQUIRES: OS=macosx
33

4-
macro function<T: ExpressibleByStringLiteral>: T = _SwiftSyntaxMacros.FunctionMacro
4+
macro function<T>: T = _SwiftSyntaxMacros.FunctionMacro where T: ExpressibleByStringLiteral
55
macro line<T: ExpressibleByIntegerLiteral>: T = _SwiftSyntaxMacros.LineMacro
66
macro column<T: ExpressibleByIntegerLiteral>: T = _SwiftSyntaxMacros.ColumnMacro
77

test/Macros/macros_diagnostics.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %target-typecheck-verify-swift -enable-experimental-feature Macros -module-name MacrosTest
2+
// REQUIRES: OS=macosx
3+
4+
macro stringify<T>(_ value: T) -> (T, String) = BuiltinMacros.StringifyMacro
5+
6+
func test(a: Int, b: Int) {
7+
// FIXME: Bad diagnostic.
8+
let s = #stringify<Int, Int>(a + b) // expected-error{{type of expression is ambiguous without more context}}
9+
}

0 commit comments

Comments
 (0)