Skip to content

Commit aa625f5

Browse files
committed
Constrain the DeclReferenceExprSyntax special case a bit
1 parent 37ce7d9 commit aa625f5

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

Diff for: Sources/TestingMacros/Support/ConditionArgumentParsing.swift

+11-1
Original file line numberDiff line numberDiff line change
@@ -321,10 +321,20 @@ private final class _ContextInserter<C, M>: SyntaxRewriter where C: MacroExpansi
321321
//
322322
// These sorts of expressions are relatively rare, so we'll allow the bug
323323
// for the sake of better diagnostics in the common case.
324-
if let memberAccessExpr = node.parent?.as(MemberAccessExprSyntax.self),
324+
if node.argumentNames == nil,
325+
let memberAccessExpr = node.parent?.as(MemberAccessExprSyntax.self),
325326
ExprSyntax(node) == memberAccessExpr.base,
326327
let functionCallExpr = memberAccessExpr.parent?.as(FunctionCallExprSyntax.self),
327328
ExprSyntax(memberAccessExpr) == functionCallExpr.calledExpression {
329+
// If the base name is an identifier and its first character is uppercase,
330+
// it is presumably a type name or module name, so don't expand it. (This
331+
// isn't a great heuristic, but it hopefully minimizes the module name
332+
// problem above.)
333+
if case .identifier = node.baseName.tokenKind,
334+
let firstCharacter = node.baseName.textWithoutBackticks.first, firstCharacter.isUppercase {
335+
return ExprSyntax(node)
336+
}
337+
328338
return _rewrite(
329339
MemberAccessExprSyntax(
330340
base: node.trimmed,

0 commit comments

Comments
 (0)