Skip to content

Commit 8eb51ce

Browse files
committed
Simplify trait emission a bit
1 parent fc87d84 commit 8eb51ce

File tree

2 files changed

+5
-22
lines changed

2 files changed

+5
-22
lines changed

Sources/TestingMacros/Support/Additions/WithAttributesSyntaxAdditions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ extension WithAttributesSyntax {
110110
}
111111

112112
/// The first `@_unavailableInEmbedded` attribute on this instance, if any.
113-
var noembeddedAttribute: AttributeSyntax? {
113+
var unavailableInEmbeddedAttribute: AttributeSyntax? {
114114
attributes(named: "_unavailableInEmbedded", inModuleNamed: "Swift").first
115115
}
116116

Sources/TestingMacros/Support/AvailabilityGuards.swift

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -140,24 +140,6 @@ private func _createAvailabilityTraitExpr(
140140
}
141141
}
142142

143-
/// Create an expression that contains a test trait for symbols that are
144-
/// unavailable in Embedded Swift.
145-
///
146-
/// - Parameters:
147-
/// - attribute: The `@_unavailableInEmbedded` attribute.
148-
/// - context: The macro context in which the expression is being parsed.
149-
///
150-
/// - Returns: An instance of `ExprSyntax` representing an instance of
151-
/// ``Trait`` that can be used to prevent a test from running in Embedded
152-
/// Swift.
153-
private func _createNoEmbeddedAvailabilityTraitExpr(
154-
from attribute: AttributeSyntax,
155-
in context: some MacroExpansionContext
156-
) -> ExprSyntax {
157-
let sourceLocationExpr = createSourceLocationExpr(of: attribute, context: context)
158-
return ".__unavailableInEmbedded(sourceLocation: \(sourceLocationExpr))"
159-
}
160-
161143
/// Create an expression that contains test traits for availability (i.e.
162144
/// `.enabled(if: ...)`).
163145
///
@@ -187,8 +169,9 @@ func createAvailabilityTraitExprs(
187169
_createAvailabilityTraitExpr(from: availability, when: .obsoleted, in: context)
188170
}
189171

190-
if let noembeddedAttribute = decl.noembeddedAttribute {
191-
result += [_createNoEmbeddedAvailabilityTraitExpr(from: noembeddedAttribute, in: context)]
172+
if let attribute = decl.unavailableInEmbeddedAttribute {
173+
let sourceLocationExpr = createSourceLocationExpr(of: attribute, context: context)
174+
result += [".__unavailableInEmbedded(sourceLocation: \(sourceLocationExpr))"]
192175
}
193176

194177
return result
@@ -313,7 +296,7 @@ func createSyntaxNode(
313296
}
314297

315298
// Handle Embedded Swift.
316-
if decl.noembeddedAttribute != nil {
299+
if decl.unavailableInEmbeddedAttribute != nil {
317300
result = """
318301
#if !hasFeature(Embedded)
319302
\(result)

0 commit comments

Comments
 (0)