Skip to content

Commit a9ee5dd

Browse files
committed
[Macros] Don't allow local names to shadow macro names.
1 parent 1a10009 commit a9ee5dd

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

lib/Sema/CSGen.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3667,10 +3667,11 @@ namespace {
36673667
) {
36683668
auto result = TypeChecker::lookupUnqualified(
36693669
CurDC, DeclNameRef(macroName), loc,
3670-
defaultUnqualifiedLookupOptions);
3670+
(defaultUnqualifiedLookupOptions |
3671+
NameLookupFlags::IncludeOuterResults));
36713672

36723673
SmallVector<OverloadChoice, 1> choices;
3673-
for (const auto &found : result) {
3674+
for (const auto &found : result.allResults()) {
36743675
if (auto macro = dyn_cast<MacroDecl>(found.getValueDecl())) {
36753676
OverloadChoice choice = OverloadChoice(Type(), macro, functionRefKind);
36763677
choices.push_back(choice);

test/Macros/macros_diagnostics.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %target-typecheck-verify-swift -enable-experimental-feature Macros -module-name MacrosTest
22
// REQUIRES: OS=macosx
33

4-
macro stringify<T>(_ value: T) -> (T, String) = BuiltinMacros.StringifyMacro
4+
macro stringify<T>(_ value: T) -> (T, String) = _SwiftSyntaxMacros.StringifyMacro
55

66
protocol P { }
77

@@ -35,3 +35,6 @@ func test(a: Int, b: Int) {
3535
let s = #stringify<Int, Int>(a + b) // expected-error{{type of expression is ambiguous without more context}}
3636
}
3737

38+
func shadow(a: Int, b: Int, stringify: Int) {
39+
_ = #stringify(a + b)
40+
}

0 commit comments

Comments
 (0)