File tree Expand file tree Collapse file tree 3 files changed +29
-21
lines changed Expand file tree Collapse file tree 3 files changed +29
-21
lines changed Original file line number Diff line number Diff line change @@ -96,10 +96,9 @@ func evaluateIfConfig(
9696 }
9797
9898 // 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+ {
103102 // Evaluate the custom condition. If the build configuration cannot answer this query, fail.
104103 return checkConfiguration ( at: identExpr) {
105104 ( active: try configuration. isCustomConditionSet ( name: ident) , syntaxErrorsAllowed: false )
@@ -499,18 +498,6 @@ private func extractImportPath(_ expression: some ExprSyntaxProtocol) throws ->
499498 throw IfConfigError . expectedModuleName ( syntax: ExprSyntax ( expression) )
500499}
501500
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-
514501/// Determine whether the given condition only involves disjunctions that
515502/// check the given config function against one of the provided values.
516503///
Original file line number Diff line number Diff line change @@ -36,13 +36,23 @@ extension LabeledExprListSyntax {
3636extension ExprSyntax {
3737 /// Whether this is a simple identifier expression and, if so, what the identifier string is.
3838 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 {
4240 return nil
4341 }
4442
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
4757 }
4858}
Original file line number Diff line number Diff line change @@ -120,6 +120,17 @@ public class EvaluateTests: XCTestCase {
120120 )
121121 ]
122122 )
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+ )
123134 }
124135
125136 func testBadExpressions( ) throws {
You can’t perform that action at this time.
0 commit comments