Hi,

Foundation in 3.0-RELEASE didn't fully resolve the renaming in SE-0086, so we 
have `RegularExpression` on Linux and `NSRegularExpression` on macOS. The 
naming is now unified in Swift 3.0.1, but there doesn’t seem to be a possible 
way to resolve the code breaking change. Consider the example below:

Currently the following code is only compatible with 3.0-RELEASE, because 
RegularExpression on Linux becomes NSRegularExpression in 3.0.1, while we 
cannot use `#if` to differentiate between 3.0 and 3.0.1.

  #if !os(macOS)
  let regex = try RegularExpression(pattern: pattern, options: [ 
.dotMatchesLineSeparators ])
  #else
  let regex = try NSRegularExpression(pattern: pattern, options: [ 
.dotMatchesLineSeparators ])
  #endif

Proposed solution:

If `#if swift(>=)` can take the third version component, we can make the code 
compatible with 3.0.1 by the following:

  #if os(macOS) || swift(>=3.0.1)
  let regex = try NSRegularExpression(pattern: pattern, options: [ 
.dotMatchesLineSeparators ])  
  #else
  let regex = try RegularExpression(pattern: pattern, options: [ 
.dotMatchesLineSeparators ])
  #endif

Additionally, we can consider supporting the == operator, so that checking only 
the version with inconsistent naming is sufficient:

  #if !os(macOS) && swift(==3.0.0)
  let regex = try RegularExpression(pattern: pattern, options: [ 
.dotMatchesLineSeparators ])
  #else
  let regex = try NSRegularExpression(pattern: pattern, options: [ 
.dotMatchesLineSeparators ])
  #endif

Impact on existing code:

`#if swift(>=X.X.X)` and `#if swift(==X.X.X)` are purely additive.

-Richard

_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to