Skip to content

[SR-6419] Use @available(*, unavailable) instead of inappropriate @available(*, obsoleted: 4.0) #1323

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

Merged
merged 1 commit into from
Nov 28, 2017

Conversation

ikesyo
Copy link
Member

@ikesyo ikesyo commented Nov 17, 2017

Fixes SR-6419.

@alblue alblue self-requested a review November 17, 2017 13:07
@alblue
Copy link
Contributor

alblue commented Nov 17, 2017

One of the reasons for having the obsoleted API is that it should allow users (who are not using the escaping closure) to perform a rename of the call. However, for trailing closures whose API is not being called this probably doesn't make sense.

I'm not sure if the right fix is to allow the obsoleted calls to be filtered from the swift compiler if it can't find an exact match, or to remove this overload (added in 7eefc15 as part of a different change).

@ianpartridge what do you think, since you reviewed the addition of the obsoleted call?

@alblue alblue requested a review from ianpartridge November 17, 2017 13:12
@ianpartridge
Copy link
Contributor

This is an interesting issue. I didn't consider the case of someone using trailing closure syntax and hence not providing the parameter name.

I'm curious how this works on Darwin, surely the same issue would be seen there? It obviously isn't seen there though, so I must be missing something...

@ikesyo
Copy link
Member Author

ikesyo commented Nov 17, 2017

I think we usually don't keep obsoleted APIs in SCLF (e.g. #1315) so

One of the reasons for having the obsoleted API is that it should allow users (who are not using the escaping closure) to perform a rename of the call.

would not be a rationale.

@alblue
Copy link
Contributor

alblue commented Nov 17, 2017

As is trivial to search in the codebase, this isn't necessarily always the case:

https://github.com/apple/swift-corelibs-foundation/search?utf8=✓&q=renamed&type=

The hints are here to allow the fix-its to move forward. Though I wonder, @ianpartridge, whether we should have used 'unavailable' rather than 'obsoleted' here? Would that solve the problem?

@@ -188,11 +188,6 @@ open class NotificationCenter: NSObject {
})
}

@available(*,obsoleted:4.0,renamed:"addObserver(forName:object:queue:using:)")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of deleting this, does changing 'obsoleted' to 'unavailable' fix the problem?

@parkera
Copy link
Contributor

parkera commented Nov 17, 2017

We used obsolete to attempt to help people migrate from Swift 2/3 and 3/4. The migrator keyed off them. The idea was, though, that as soon as that release was in the past, we could remove the obsolete API.

@alblue
Copy link
Contributor

alblue commented Nov 17, 2017

You get the same effect with unavailable as well, except that new code cannot refer to unavailable (but in this case, it can, which is causing the error).

@ianpartridge
Copy link
Contributor

@ikesyo @parkera do you think @available(*, unavailable, renamed: "addObserver(forName:object:queue:using:)") would be a better solution? Or should we just merge this PR?

@alblue
Copy link
Contributor

alblue commented Nov 21, 2017 via email

@ikesyo
Copy link
Member Author

ikesyo commented Nov 21, 2017

Or maybe we should explicitly use swift instead of *.

https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Attributes.html

You can also use an asterisk (*) to indicate the availability of the declaration on all of the platform names listed above. An available attribute specifying a Swift version availability can’t use the asterisk.

@ikesyo ikesyo changed the title [SR-6419] Remove obsoleted NotificationCenter.addObserver(forName:object:queue:usingBlock:) [SR-6419] swift should be used instead of * for @available Nov 23, 2017
@ikesyo
Copy link
Member Author

ikesyo commented Nov 23, 2017

Updated to use @available(swift, obsoleted: 4.0) as I said above.

@ikesyo ikesyo requested a review from alblue November 23, 2017 10:34
@ikesyo
Copy link
Member Author

ikesyo commented Nov 23, 2017

@alblue @ianpartridge Please re-check this.

@ikesyo
Copy link
Member Author

ikesyo commented Nov 23, 2017

@swift-ci Please test

@ikesyo
Copy link
Member Author

ikesyo commented Nov 23, 2017

cc @parkera

@alblue
Copy link
Contributor

alblue commented Nov 23, 2017 via email

@ikesyo
Copy link
Member Author

ikesyo commented Nov 23, 2017

Hm then I’m not sure why obsoleted was used here if unavailable is preferable but I will do it anyway.

…@available(*, obsoleted: 4.0)`

`swift` should be used instead of `*` with `obsoleted: 4.0` here. But somehow use `unavailable` (as requested).
@ikesyo ikesyo changed the title [SR-6419] swift should be used instead of * for @available [SR-6419] Use @available(*, unavailable) instead of inappropriate @available(*, obsoleted: 4.0) Nov 23, 2017
@ikesyo ikesyo requested review from alblue and removed request for alblue November 23, 2017 13:53
@ikesyo
Copy link
Member Author

ikesyo commented Nov 23, 2017

@alblue Done

@ikesyo
Copy link
Member Author

ikesyo commented Nov 23, 2017

@swift-ci Please test

@alblue
Copy link
Contributor

alblue commented Nov 23, 2017

@swift-ci please test

@alblue
Copy link
Contributor

alblue commented Nov 27, 2017

@swift-ci please test and merge

2 similar comments
@spevans
Copy link
Contributor

spevans commented Nov 27, 2017

@swift-ci please test and merge

@alblue
Copy link
Contributor

alblue commented Nov 28, 2017

@swift-ci please test and merge

@swift-ci swift-ci merged commit f1ed2a5 into swiftlang:master Nov 28, 2017
@ikesyo ikesyo deleted the SR-6419 branch November 28, 2017 10:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants