Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
swift-ci opened this issue Jun 1, 2016 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Jun 1, 2016

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:

  • SR-826 Conditional compilation over methods seem to do syntax check but only a simple one

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

}
@lilyball
Copy link
Mannequin

lilyball mannequin commented Jun 1, 2016

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

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

1 participant