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-15051] Swift should suggest updating existing @available attribute when you use an insufficiently available declaration #57378

Open
beccadax opened this issue Aug 10, 2021 · 3 comments · May be fixed by #72524
Labels
availability The @available attribute and availability checking in general compiler The Swift compiler itself diagnostics QoI Bug: Diagnostics Quality of Implementation fix-its Feature: diagnostic fix-its good first issue Good for newcomers improvement type checker Area → compiler: Semantic analysis

Comments

@beccadax
Copy link
Contributor

beccadax commented Aug 10, 2021

Previous ID SR-15051
Radar rdar://problem/81802673
Original Reporter @beccadax
Type Improvement
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Improvement, DiagnosticsQoI, StarterBug
Assignee mininny (JIRA)
Priority Medium

md5: 9db411fbe711e822a955f04325204e6d

Issue Description:

Currently, fixAvailabilityForDecl() in TypeCheckAvailability.cpp exits early if there is already an @available attribute on the declaration, with a comment noting work that should be done in the future:

/// Emit a diagnostic note and Fix-It to add an @available attribute
/// on the given declaration for the given version range.
static void fixAvailabilityForDecl(SourceRange ReferenceRange, const Decl *D,
                                   const VersionRange &RequiredRange,
                                   ASTContext &Context) {
  // ...irrelevant code omitted...

  if (getActiveAvailableAttribute(D, Context)) {
    // For QoI, in future should emit a fixit to update the existing attribute.
    return;
  }

Indeed, we should make this change. For instance, if you give the compiler this code:

@available(macOS 42, *) func foo() {}

@available(macOS 12, *) func bar() {
    foo()
}

Swift should emit a note with a fix-it replacing "macOS 12" with "macOS 42".

Your implementation, should you choose to commit it, should test not only this easy case with one simple @available attribute, but also cases with multiple OSes and long-form @available attributes. You will certainly need to update some existing tests; those might adequately cover this, but I'm not sure.

@typesanitizer
Copy link

@swift-ci create

@swift-ci
Copy link
Contributor

Comment by Minhyuk Kim (JIRA)

Created a draft PR here: #38887

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@CrazyFanFan
Copy link
Contributor

Hi @beccadax I have resolved this issues. Please have a look at my Pull Request #72524 .

@AnthonyLatsis AnthonyLatsis added fix-its Feature: diagnostic fix-its type checker Area → compiler: Semantic analysis availability The @available attribute and availability checking in general labels Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
availability The @available attribute and availability checking in general compiler The Swift compiler itself diagnostics QoI Bug: Diagnostics Quality of Implementation fix-its Feature: diagnostic fix-its good first issue Good for newcomers improvement type checker Area → compiler: Semantic analysis
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants