[SR-15051] Swift should suggest updating existing @available attribute when you use an insufficiently available declaration
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 48/100
- Issue type
- Feature
- Clarity
- Clearly specified
- Activity status
- Stale
- Domain
- compilers, testing-qa
Research direction
Start in TypeCheckAvailability.cpp at fixAvailabilityForDecl() and inspect the existing availability diagnostic tests. Trace the early return for declarations with an existing @available attribute, then cover simple, multiple-OS, and long-form attributes. Done means diagnostics suggest replacing the insufficient availability version and the relevant tests pass.
Written by the indexing model from the issue text.
Description
| 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.
- Dominant language
- Swift
- Stars
- 70.4k
- Forks
- 10.8k
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 461
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from swiftlang/swift
-
triage needed
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
triage needed
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Foundation Windows
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
triage needed
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
triage needed
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Similar issues
-
type: docs
Difficulty 1/5 Under an hour Newbie friendliness 95/100
googleapis/google-cloud-swift#971 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
bitcoindevkit/bdk-ffi#1125 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
mozilla-mobile/firefox-ios#35743 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
manaflow-ai/cmux#13417 ·
-
triage
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
ionic-team/capacitor#8616 ·