Skip to content

Commit 983efcd

Browse files
authored
Fully-qualify reference to 'Comment' type in #expect expansion when comment argument isn't a string literal (#1645)
This fixes a build error which can arise in the code emitted by `#expect` when the `comment` argument is not a string literal and the module the `#expect` appears in has a custom type visible named `Comment`, conflicting with the testing library's built-in type by that name. Fixes #1641 ### Checklist: - [x] Code and documentation should follow the style of the [Style Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md). - [x] If public symbols are renamed or modified, DocC references should be updated.
1 parent 62d7c94 commit 983efcd

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

Sources/TestingMacros/ConditionMacro.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ extension ConditionMacro {
177177
// the resulting comment array.
178178
checkArguments.append(Argument(
179179
label: "comments",
180-
expression: #"(\#(commentsArrayExpr) as [Comment?]).compactMap(\.self)"#
180+
expression: #"(\#(commentsArrayExpr) as [Testing.Comment?]).compactMap(\.self)"#
181181
))
182182
} else {
183183
checkArguments.append(Argument(label: "comments", expression: commentsArrayExpr))

Tests/TestingTests/MiscellaneousTests.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,4 +637,14 @@ struct MiscellaneousTests {
637637
}
638638
#expect(duration < .seconds(1))
639639
}
640+
641+
@Test func `Expectation with a non-string literal comment and ambiguous 'Comment' type`() {
642+
let comment: Comment = "foo"
643+
do {
644+
// Declare a custom type whose name conflicts with the testing library's
645+
// built-in Comment type.
646+
struct Comment {}
647+
#expect(true as Bool, comment)
648+
}
649+
}
640650
}

0 commit comments

Comments
 (0)