File tree 3 files changed +29
-21
lines changed 3 files changed +29
-21
lines changed Original file line number Diff line number Diff line change @@ -96,10 +96,9 @@ func evaluateIfConfig(
96
96
}
97
97
98
98
// Declaration references are for custom compilation flags.
99
- if let identExpr = condition. as ( DeclReferenceExprSyntax . self) {
100
- // FIXME: Need a real notion of an identifier.
101
- let ident = identExpr. baseName. text
102
-
99
+ if let identExpr = condition. as ( DeclReferenceExprSyntax . self) ,
100
+ let ident = identExpr. simpleIdentifier
101
+ {
103
102
// Evaluate the custom condition. If the build configuration cannot answer this query, fail.
104
103
return checkConfiguration ( at: identExpr) {
105
104
( active: try configuration. isCustomConditionSet ( name: ident) , syntaxErrorsAllowed: false )
@@ -499,18 +498,6 @@ private func extractImportPath(_ expression: some ExprSyntaxProtocol) throws ->
499
498
throw IfConfigError . expectedModuleName ( syntax: ExprSyntax ( expression) )
500
499
}
501
500
502
- extension DeclReferenceExprSyntax {
503
- /// If this declaration reference is a simple identifier, return that
504
- /// string.
505
- fileprivate var simpleIdentifier : String ? {
506
- guard argumentNames == nil else {
507
- return nil
508
- }
509
-
510
- return baseName. text
511
- }
512
- }
513
-
514
501
/// Determine whether the given condition only involves disjunctions that
515
502
/// check the given config function against one of the provided values.
516
503
///
Original file line number Diff line number Diff line change @@ -36,13 +36,23 @@ extension LabeledExprListSyntax {
36
36
extension ExprSyntax {
37
37
/// Whether this is a simple identifier expression and, if so, what the identifier string is.
38
38
var simpleIdentifierExpr : String ? {
39
- guard let identExpr = self . as ( DeclReferenceExprSyntax . self) ,
40
- identExpr. argumentNames == nil
41
- else {
39
+ guard let identExpr = self . as ( DeclReferenceExprSyntax . self) else {
42
40
return nil
43
41
}
44
42
45
- // FIXME: Handle escaping here.
46
- return identExpr. baseName. text
43
+ return identExpr. simpleIdentifier
44
+ }
45
+ }
46
+
47
+ extension DeclReferenceExprSyntax {
48
+ /// If this declaration reference is a simple identifier, return that
49
+ /// string.
50
+ var simpleIdentifier : String ? {
51
+ guard argumentNames == nil else {
52
+ return nil
53
+ }
54
+
55
+ /// FIXME: Make this an Identifier so we handle escaping properly.
56
+ return baseName. text
47
57
}
48
58
}
Original file line number Diff line number Diff line change @@ -120,6 +120,17 @@ public class EvaluateTests: XCTestCase {
120
120
)
121
121
]
122
122
)
123
+ assertIfConfig (
124
+ " BAR(_:) " ,
125
+ . unparsed,
126
+ diagnostics: [
127
+ DiagnosticSpec (
128
+ message: " invalid conditional compilation expression " ,
129
+ line: 1 ,
130
+ column: 1
131
+ )
132
+ ]
133
+ )
123
134
}
124
135
125
136
func testBadExpressions( ) throws {
You can’t perform that action at this time.
0 commit comments