Commit Graph

16 Commits

Author SHA1 Message Date
Anthony Latsis
96be6cf6a6 DiagnosticEngine: Do not describe an accessor's storage for %kindonly
This is the desired behavior is most cases. In the future, we should
consider adding format specifiers for short/detailed descriptions.
2025-04-05 12:31:19 +01:00
Allan Shortlidge
0fd2f3fc1c Sema: Diagnose @_spi_available on declarations that cannot be unavailable.
The attribute makes the declaration unavailable from the perspective of clients
of the module's public interface and was creating a loophole that admitted
inappropriate unavailability.
2025-03-07 19:44:48 -08:00
Allan Shortlidge
21837e9fde Sema: Reject @available on observing accessors.
Marking an observer unavailable (or potentially unavailable) has no effect
since the compiler emits calls to them unconditionally.

Resolves rdar://80337141.
2024-09-11 16:42:48 -07:00
Allan Shortlidge
0dbbb68171 Sema: Fix accessor availability checking in argument lists.
The changes in https://github.com/apple/swift/pull/72410 caused a regression
when checking availability in the following example:

```
// warning: Setter for 'hasDeprecatedSetter' is deprecated: ...
x[y.hasDeprecatedSetter] = ...
```

The result of `y.hasDeprecatedSetter` is being passed as an argument to the
subscript and its setter will not be called. To fix this,
`ExprAvailabilityWalker` now consistently creates a new default
`MemberAccessContext` when descending into any `Argument`, since the access
context for the expressions surrounding the call should not affect the
arguments to the call.

Additionally, `MemberAccessContext` has been refactored to better model context
state transitions. Instead of only modeling which accessors will be called, the
enumeration's members now reflect the possible states that
`ExprAvailabilityWalker` can be in during its traversal. This should hopefully
make it easier to follow the logic for traversal of `LoadExpr`s and arguments.

Resolves rdar://130487998.
2024-06-27 11:13:52 -07:00
Allan Shortlidge
0673e99839 Tests: Add tests exercising subscripts to availability_accessors.swift.
Some of the test cases demonstrate the issue reported in rdar://130487998.
2024-06-27 11:13:52 -07:00
Allan Shortlidge
2953a26b28 Tests: Add tests exercising subscripts to availability_accessors.swift.
Some of the test cases demonstrate the issue reported in rdar://130487998.
2024-06-27 11:13:52 -07:00
Allan Shortlidge
31df22f5ec Sema: A LoadExpr enclosing a call does not affect the arguments.
Fixes missing setter availability diagnostics in some edge cases.
2024-06-25 11:08:20 -07:00
Allan Shortlidge
89e31cd818 Tests: Expand test coverage of inout parameters availability_accessors.swift. 2024-06-25 10:55:29 -07:00
Allan Shortlidge
46e7f7f014 Tests: Consolidate takesInOut() helper in availability_accessors.swift.
NFC.
2024-06-25 09:20:52 -07:00
Allan Shortlidge
6e16075692 Sema: Suppress set accessor availability diagnostics in LoadExprs.
This fixes a regression from https://github.com/swiftlang/swift/pull/72369.
The compiler now incorrectly diagnoses use of an unavailable setter in this
example:

```
func increaseBrightness(in window: UIWindow) {
  // warning: setter for 'screen' was deprecated in iOS 13.0
  window.screen.brightness = 1.0
}
```

While the setter is deprecated, it would not be called in the generated code
since `screen` is a reference type and there is no writeback through the setter
for `screen` after setting `brightness`.

Resolves rdar://129679658
2024-06-25 09:20:34 -07:00
Allan Shortlidge
e055b383d2 Tests: Add test cases to availability_accessors.swift using classes.
Many of the new FIXMEs demonstrate the regression reported in rdar://129679658.
2024-06-25 09:17:04 -07:00
Allan Shortlidge
f0ff799251 Tests: Refactor availability_accessors.swift. 2024-06-25 09:17:04 -07:00
Allan Shortlidge
c7f0c58615 Sema: Diagnose availability of accessors in chained assignments.
In the following example, the writeback via the property `b` should be
diagnosed since `b`'s setter is unavailable:

```
struct A {
  struct B {
    var x: Int = 0
  }

  private var _b: B = B()
  var b: B {
    get { _b }
    @available(*, unavailable) set {
      _b = newValue
    }
  }
}

var a = A()
a.b.x = 1
```

Resolves rdar://125019717
2024-03-19 17:10:44 -07:00
Allan Shortlidge
ad940abf4d Sema: Diagnose availability of storage accessors for key paths.
Fixes the missing diagnostic about the availability of the setter of `x` in the
following example:

```
struct S {
  var x: Int {
    get { 0 }
    @available(*, unavailable) set {}
  }
}

var s = S()
s[keyPath: \.x] = 1
```

Resolves rdar://124977727
2024-03-19 17:10:44 -07:00
Allan Shortlidge
5a232391f5 Sema: Do not diagnose set accessor availability for InOutExprs inside of LoadExprs.
The recent deprecation of the set accessor for `CommandLine.arguments` exposed
a bug in availability checking:

```
 for arg in CommandLine.arguments[1...] {
                      ╰─ warning: setter for 'arguments' is deprecated: ...
```

The parser generates an `InOutExpr` in the AST for the subscript access in the
code above and the availabilty checker was unconditionally diagnosing set
accessors for `InOutExprs`, resulting in spurious availability warnings for
read-only accesses of properties. The fix is to check whether there is an
enclosing `LoadExpr` in the AST and only diagnose the getter accessor in that
case.

Resolves rdar://124566405
2024-03-18 16:18:08 -07:00
Allan Shortlidge
bab6518bd7 Sema: Add a test for accessor availability diagnostics.
This test documents the current behavior of availability diagnostics for
generalized accessors, including some bugs which have been called out as
FIXMEs.
2024-03-18 16:18:08 -07:00