Commit Graph

4 Commits

Author SHA1 Message Date
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