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 97565b0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
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
10 changes: 4 additions & 6 deletions Tests/TestingTests/Support/CartesianProductTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ struct CartesianProductTests {
// Test the size of the product is correct.
let (c1, c2, product) = computeCartesianProduct()
#expect(product.underestimatedCount == c1.underestimatedCount * c2.underestimatedCount)
let productCount = Array(product).count
#expect(productCount == c1.count * c2.count)
#expect(productCount == 26 * 100)
#expect(Array(product).count == c1.count * c2.count)
#expect(Array(product).count == 26 * 100)
}

@Test("First element is correct")
Expand All @@ -59,9 +58,8 @@ struct CartesianProductTests {

// NOTE: we need to break out the tuple elements because tuples aren't
// directly equatable.
let productArray = Array(product)
#expect(productArray.map(\.0) == possibleValues.map(\.0))
#expect(productArray.map(\.1) == possibleValues.map(\.1))
#expect(Array(product).map(\.0) == possibleValues.map(\.0))
#expect(Array(product).map(\.1) == possibleValues.map(\.1))
}

@Test("Cartesian product with empty first input is empty")
Expand Down

0 comments on commit 97565b0

Please sign in to comment.