From aa625f58fd8f44ab86722d8908c639985d436ce0 Mon Sep 17 00:00:00 2001 From: Jonathan Grynspan Date: Fri, 24 Jan 2025 16:51:48 -0500 Subject: [PATCH] Constrain the DeclReferenceExprSyntax special case a bit --- .../Support/ConditionArgumentParsing.swift | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Sources/TestingMacros/Support/ConditionArgumentParsing.swift b/Sources/TestingMacros/Support/ConditionArgumentParsing.swift index 8d5bdd483..a860af52d 100644 --- a/Sources/TestingMacros/Support/ConditionArgumentParsing.swift +++ b/Sources/TestingMacros/Support/ConditionArgumentParsing.swift @@ -321,10 +321,20 @@ private final class _ContextInserter: SyntaxRewriter where C: MacroExpansi // // These sorts of expressions are relatively rare, so we'll allow the bug // for the sake of better diagnostics in the common case. - if let memberAccessExpr = node.parent?.as(MemberAccessExprSyntax.self), + if node.argumentNames == nil, + let memberAccessExpr = node.parent?.as(MemberAccessExprSyntax.self), ExprSyntax(node) == memberAccessExpr.base, let functionCallExpr = memberAccessExpr.parent?.as(FunctionCallExprSyntax.self), ExprSyntax(memberAccessExpr) == functionCallExpr.calledExpression { + // If the base name is an identifier and its first character is uppercase, + // it is presumably a type name or module name, so don't expand it. (This + // isn't a great heuristic, but it hopefully minimizes the module name + // problem above.) + if case .identifier = node.baseName.tokenKind, + let firstCharacter = node.baseName.textWithoutBackticks.first, firstCharacter.isUppercase { + return ExprSyntax(node) + } + return _rewrite( MemberAccessExprSyntax( base: node.trimmed,