Skip to content

Commit 97565b0

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

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

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,

Tests/TestingTests/Support/CartesianProductTests.swift

+4-6
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ struct CartesianProductTests {
3131
// Test the size of the product is correct.
3232
let (c1, c2, product) = computeCartesianProduct()
3333
#expect(product.underestimatedCount == c1.underestimatedCount * c2.underestimatedCount)
34-
let productCount = Array(product).count
35-
#expect(productCount == c1.count * c2.count)
36-
#expect(productCount == 26 * 100)
34+
#expect(Array(product).count == c1.count * c2.count)
35+
#expect(Array(product).count == 26 * 100)
3736
}
3837

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

6059
// NOTE: we need to break out the tuple elements because tuples aren't
6160
// directly equatable.
62-
let productArray = Array(product)
63-
#expect(productArray.map(\.0) == possibleValues.map(\.0))
64-
#expect(productArray.map(\.1) == possibleValues.map(\.1))
61+
#expect(Array(product).map(\.0) == possibleValues.map(\.0))
62+
#expect(Array(product).map(\.1) == possibleValues.map(\.1))
6563
}
6664

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

0 commit comments

Comments
 (0)