Skip to content

Commit

Permalink
Constrain the DeclReferenceExprSyntax special case a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
grynspan committed Jan 24, 2025
1 parent 37ce7d9 commit aa625f5
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Sources/TestingMacros/Support/ConditionArgumentParsing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,20 @@ private final class _ContextInserter<C, M>: 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,
Expand Down

0 comments on commit aa625f5

Please sign in to comment.