swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.62k stars 10.37k forks source link

[SR-1656] Build Configuration statement breaks method overloading inside of a type #44265

Closed swift-ci closed 8 years ago

swift-ci commented 8 years ago
Previous ID SR-1656
Radar None
Original Reporter MonocularVision (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug | |Assignee | MonocularVision (JIRA) | |Priority | Medium | md5: 1d9231862676d4fba1627315856a860b

duplicates:

Issue Description:

Overloading a method seems to break when using a build configuration (and the build configuration is NOT defined). In the following code the SCOOBY_DOO command line flag was not passed:

class TestClass {

#if SCOOBY_DOO

  func log(urlRequest: NSURLRequest) {

  }

  func log(responseData: NSData) {

  }

  func log(error: NSError) {

  }

#endif

}

The code fails with:

main.swift:11:8: error: definition conflicts with previous value
  func log(responseData: NSData) {
       ^
main.swift:7:8: note: previous definition of 'log' is here
  func log(urlRequest: NSURLRequest) {
       ^
main.swift:15:8: error: definition conflicts with previous value
  func log(error: NSError) {
       ^
main.swift:7:8: note: previous definition of 'log' is here
  func log(urlRequest: NSURLRequest) {
       ^

Note that if SCOOBY_DOO is defined, then the code compiles. Also, this works in either case if these methods are not inside of a type and simply top level functions. It also works if you individually wrap each overloaded method with the build configuration flag like this:

class TestClass {

#if SCOOBY_DOO

  func log(urlRequest: NSURLRequest) {

  }

#endif

#if SCOOBY_DOO

  func log(responseData: NSData) {

  }

#endif

#if SCOOBY_DOO

  func log(error: NSError) {

  }

#endif

}
05262b81-54a9-4fe1-bf6a-96f8042de10e commented 8 years ago

This is a duplicate of SR-826, which was already fixed for Swift 3.