swift
swift copied to clipboard
[Diagnostics] Add support for updating the existing 'available' attribute.
Revise the context to recommend an update to the existing 'available' attribute.
Consider the following code:
@available(macOS 42, *)
func foo() {}
@available(macOS 12, *)
func bar() {
foo()
}
A new fix-it suggests altering the '@available' attribute of the global function on macOS from 12 to 42.
11 │ @available(macOS 12, *)
12 │ func bar() {
13 │ foo()
│ ├─ error: 'foo()' is only available in macOS 42 or newer
│ ├─ note: add 'if #available' version check
│ ╰─ note: change the @available attribute of the global function on macOS from 12 to 42
14 │ }
Resolves #57378
@swift-ci please test
Thank you for your response, @beccadax and @LucianoPAlmeida. I made some updates This patch includes the following updates:
- Renamed the function
update_availability_attribute
toavailability_update_attribute
. - Read the version string using
Attr->Introduced->getAsString()
. - Skip update, if
Attr->getRange()
does not overlap withAttr->IntroducedRange
. - Currently, I haven't found a more concise way to fetch
ReferenceName
, and I would greatly appreciate any suggestions in the comments.
Thank you for your time and assistance.