Skip to content

Commit 624c3d0

Browse files
committed
Merge remote-tracking branch 'origin/main' into rebranch
2 parents c02995a + 10a5cc9 commit 624c3d0

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,6 +1331,13 @@ static bool contextMayExpandOperator(
13311331
else
13321332
return false;
13331333

1334+
// If the context declaration itself is within a macro expansion, it may
1335+
// have an operator.
1336+
if (auto sourceFile = dc->getParentSourceFile()) {
1337+
if (sourceFile->getFulfilledMacroRole())
1338+
return true;
1339+
}
1340+
13341341
ASTContext &ctx = dc->getASTContext();
13351342
auto potentialExpansions = evaluateOrDefault(
13361343
ctx.evaluator, PotentialMacroExpansionsInContextRequest{decl},

test/Macros/Inputs/syntax_macro_definitions.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,6 +1595,28 @@ public struct DefineStructWithUnqualifiedLookupMacro: DeclarationMacro {
15951595
}
15961596
}
15971597

1598+
public struct DefineComparableTypeMacro: DeclarationMacro {
1599+
public static func expansion(
1600+
of node: some FreestandingMacroExpansionSyntax,
1601+
in context: some MacroExpansionContext
1602+
) throws -> [DeclSyntax] {
1603+
return ["""
1604+
struct ComparableType: Comparable {
1605+
static func <(lhs: ComparableType, rhs: ComparableType) -> Bool {
1606+
return false
1607+
}
1608+
1609+
enum Inner: String, Comparable {
1610+
case hello = "hello"
1611+
static func <(lhs: ComparableType.Inner, rhs: ComparableType.Inner) -> Bool {
1612+
return lhs.rawValue < rhs.rawValue
1613+
}
1614+
}
1615+
}
1616+
"""]
1617+
}
1618+
}
1619+
15981620
public struct AddMemberWithFixIt: MemberMacro {
15991621
public static func expansion<
16001622
Declaration: DeclGroupSyntax, Context: MacroExpansionContext

test/Macros/macro_expand.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,3 +567,11 @@ struct DeprecatedStructWrapper {
567567
#deprecatedStringifyAsDeclMacro(1 + 1)
568568
}
569569
#endif
570+
571+
572+
@freestanding(declaration, names: named(ComparableType))
573+
macro DefineComparableType() = #externalMacro(module: "MacroDefinition", type: "DefineComparableTypeMacro")
574+
575+
struct HasNestedType {
576+
#DefineComparableType
577+
}

0 commit comments

Comments
 (0)