Skip to content

Commit d494c04

Browse files
committed
Attempt to work around compiler regression causing CI failure.
This PR attempts to work around the compiler regression reported in rdar://135346598 that is currently causing our macOS CI jobs to fail.
1 parent 20c4440 commit d494c04

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

Sources/TestingMacros/Support/AttributeDiscovery.swift

+13-8
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,43 @@ import SwiftSyntaxMacros
1717
/// If the developer specified Self.something as an argument to the `@Test` or
1818
/// `@Suite` attribute, we will currently incorrectly infer Self as equalling
1919
/// the `__TestContainer` type we emit rather than the type containing the
20-
/// test. This class strips off `Self.` wherever that occurs.
20+
/// test. This class strips off `Self.` wherever that occurs and, if possible,
21+
/// replaces it with the actual containing type name.
2122
///
2223
/// Note that this operation is technically incorrect if a subexpression of the
2324
/// attribute declares a type and refers to it with `Self`. We accept this
2425
/// constraint as it is unlikely to pose real-world issues and is generally
2526
/// solvable by using an explicit type name instead of `Self`.
26-
///
27-
/// This class should instead replace `Self` with the name of the containing
28-
/// type when rdar://105470382 is resolved.
2927
private final class _SelfRemover<C>: SyntaxRewriter where C: MacroExpansionContext {
3028
/// The macro context in which the expression is being parsed.
3129
let context: C
3230

31+
/// The type with which to replace `Self`.
32+
let typeExpr: TypeExprSyntax?
33+
3334
/// Initialize an instance of this class.
3435
///
3536
/// - Parameters:
3637
/// - context: The macro context in which the expression is being parsed.
3738
/// - viewMode: The view mode to use when walking the syntax tree.
3839
init(in context: C) {
3940
self.context = context
41+
self.typeExpr = context.typeOfLexicalContext.map { TypeExprSyntax(type: $0) }
4042
}
4143

4244
override func visit(_ node: MemberAccessExprSyntax) -> ExprSyntax {
4345
if let base = node.base?.as(DeclReferenceExprSyntax.self) {
4446
if base.baseName.tokenKind == .keyword(.Self) {
45-
// We cannot currently correctly convert Self.self into the expected
46-
// type name, but once rdar://105470382 is resolved we can replace the
47-
// base expression with the typename here (at which point Self.self
48-
// ceases to be an interesting case anyway.)
47+
if let typeExpr {
48+
// Replace Self with the actual type name.
49+
return ExprSyntax(node.with(\.base, ExprSyntax(typeExpr)))
50+
}
51+
// We don't know the enclosing type name, so just strip Self and hope
52+
// the compiler is happy with the leading dot syntax.
4953
return ExprSyntax(node.declName)
5054
}
5155
} else if let base = node.base?.as(MemberAccessExprSyntax.self) {
56+
// Recursively walk into the base expression.
5257
return ExprSyntax(node.with(\.base, visit(base)))
5358
}
5459
return ExprSyntax(node)

0 commit comments

Comments
 (0)