swift icon indicating copy to clipboard operation
swift copied to clipboard

[Diagnostics] Add support for updating the existing 'available' attribute.

Open CrazyFanFan opened this issue 11 months ago • 2 comments

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

CrazyFanFan avatar Mar 22 '24 20:03 CrazyFanFan

@swift-ci please test

beccadax avatar Mar 28 '24 20:03 beccadax

Thank you for your response, @beccadax and @LucianoPAlmeida. I made some updates This patch includes the following updates:

  1. Renamed the function update_availability_attribute to availability_update_attribute.
  2. Read the version string using Attr->Introduced->getAsString().
  3. Skip update, if Attr->getRange() does not overlap with Attr->IntroducedRange.
  4. 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.

CrazyFanFan avatar Apr 01 '24 12:04 CrazyFanFan