File tree 4 files changed +43
-9
lines changed
4 files changed +43
-9
lines changed Original file line number Diff line number Diff line change @@ -44,7 +44,8 @@ public enum CanImportVersion {
44
44
/// be imported is a complicated task only implemented in the Swift compiler.
45
45
/// Therefore, queries are permitted to throw an error to report when they
46
46
/// cannot answer a query, in which case this error will be reported to
47
- /// the caller.
47
+ /// the caller and the condition will be treated as being "false", so the
48
+ /// code covered by the condition will be inactive.
48
49
public protocol BuildConfiguration {
49
50
/// Determine whether a given custom build condition has been set.
50
51
///
Original file line number Diff line number Diff line change @@ -24,15 +24,18 @@ extension SyntaxProtocol {
24
24
/// func f()
25
25
/// #elseif B
26
26
/// func g()
27
+ /// #elseif compiler(>= 12.0)
28
+ /// please print the number after 41
27
29
/// #endif
28
30
/// #else
29
31
/// #endif
30
32
///
31
33
/// If the configuration options `DEBUG` and `B` are provided, but `A` is not,
32
- /// the results will be contain:
33
- /// - Active region for the `#if DEBUG`
34
- /// - Inactive region for the `#if A`
35
- /// - Active region for the `#elseif B`
34
+ /// and the compiler version is less than 12.0, the results will be contain:
35
+ /// - Active region for the `#if DEBUG`.
36
+ /// - Inactive region for the `#if A`.
37
+ /// - Active region for the `#elseif B`.
38
+ /// - Unparsed region for the `#elseif compiler(>= 12.0)`.
36
39
/// - Inactive region for the final `#else`.
37
40
public func configuredRegions(
38
41
in configuration: some BuildConfiguration
Original file line number Diff line number Diff line change @@ -23,13 +23,19 @@ extension SyntaxProtocol {
23
23
/// #if DEBUG
24
24
/// #if A
25
25
/// func f()
26
- /// #elseif B
27
- /// func g()
26
+ /// #elseif B
27
+ /// func g()
28
+ /// #elseif compiler(>= 12.0)
29
+ /// please print the number after 41
28
30
/// #endif
29
31
/// #endif
30
32
///
31
33
/// a call to `isActive` on the syntax node for the function `g` would return `active` when the
32
34
/// configuration options `DEBUG` and `B` are provided, but `A` is not.
35
+ ///
36
+ /// If the compiler version is smaller than 12.0, then `isActive` on any of the tokens within
37
+ /// that `#elseif` block would return "unparsed", because that syntax should not (conceptually)
38
+ /// be parsed.
33
39
public func isActive(
34
40
in configuration: some BuildConfiguration
35
41
) -> ( state: IfConfigRegionState , diagnostics: [ Diagnostic ] ) {
Original file line number Diff line number Diff line change @@ -216,9 +216,9 @@ public class EvaluateTests: XCTestCase {
216
216
assertIfConfig ( " canImport(SwiftSyntax, _version: 5.10) " , . inactive)
217
217
assertIfConfig ( #"canImport(SwiftSyntax, _version: "5.9")"# , . active)
218
218
assertIfConfig ( " canImport(SwiftSyntax, _underlyingVersion: 5009) " , . active)
219
- assertIfConfig ( " canImport(SwiftSyntax, _underlyingVersion: 5009.10 " , . inactive)
219
+ assertIfConfig ( " canImport(SwiftSyntax, _underlyingVersion: 5009.10) " , . inactive)
220
220
assertIfConfig (
221
- " canImport(SwiftSyntax, _underlyingVersion: 5009.10.5.4.2.3.5 " ,
221
+ " canImport(SwiftSyntax, _underlyingVersion: 5009.10.5.4.2.3.5) " ,
222
222
. inactive,
223
223
diagnostics: [
224
224
DiagnosticSpec (
@@ -229,6 +229,30 @@ public class EvaluateTests: XCTestCase {
229
229
)
230
230
]
231
231
)
232
+ assertIfConfig (
233
+ " canImport(SwiftSyntax, _version: 20A301) " ,
234
+ . unparsed,
235
+ diagnostics: [
236
+ DiagnosticSpec (
237
+ message: " 'canImport' version check has invalid version '20A301' " ,
238
+ line: 1 ,
239
+ column: 34 ,
240
+ severity: . error
241
+ )
242
+ ]
243
+ )
244
+ assertIfConfig (
245
+ #"canImport(SwiftSyntax, _version: "20A301")"# ,
246
+ . unparsed,
247
+ diagnostics: [
248
+ DiagnosticSpec (
249
+ message: #"'canImport' version check has invalid version '"20A301"'"# ,
250
+ line: 1 ,
251
+ column: 34 ,
252
+ severity: . error
253
+ )
254
+ ]
255
+ )
232
256
}
233
257
}
234
258
You can’t perform that action at this time.
0 commit comments