Commit Graph

10 Commits

Author SHA1 Message Date
Anthony Latsis
d98a76172d Gardening: Migrate test suite to GH issues: Sema (1/2) 2022-09-02 11:00:19 +03:00
Nathan Hawes
bce68fa4e5 [IDE][Refactoring] Handle 'callAsFunction' specially in syntactic rename.
This change makes us treat it exactly as we do 'init'. We don't allow renaming the base name,
and don't fail if the basename doesn't match for calls.

Also:
  - explicit init calls/references like `MyType.init(42)` are now reported with
    'init' as a keywordBase range, rather than nothing.
  - cursor info no longer reports rename as available on init/callAsFunction
    calls without arguments, as there's nothing to rename in that case.
  - Improved detection of when a referenced function is a call (rather than
    reference) across syntactic rename, cursor-info, and indexing.

Resolves rdar://problem/60340429
2020-04-12 17:14:15 -07:00
Suyash Srijan
543d649278 [Diagnostics] Warn when the result of a Void-returning function is ignored (by assigning into '_') (#29576) 2020-02-04 20:19:37 +00:00
Pavel Yaskevich
184e238707 [Diagnostics] Improve diagnostics for mutating callAsFunction used on r-value 2019-12-06 16:43:18 -08:00
Hamish Knight
8a83440ce1 [CS] Resolve callees for callAsFunction ".member" exprs
Apply the same checks as ApplyExprs to
UnresolvedMemberExprs in getCalleeLocator to
resolve callees in cases where they're used with
`callAsFunction` in addition to a weird edge case
where we currently allow them with constructor
calls, e.g:

```
struct S {
  static let s = S.self
}

let x: S = .s()
```

Arguably we should be representing ".member()"
expressions with an UnresolvedMemberExpr + CallExpr,
which would avoid the need to apply these special
cases, and reject the above syntax for not using
an explicit ".init". Doing so will likely require
a bit of hacking in CSGen though.

Resolves SR-11909.
2019-12-06 11:21:37 -08:00
Hamish Knight
2d7a088c91 Don't check access control for isCallableNominalType
We still want the constraint system to try looking up
a callAsFunction method even if it's inaccessible, as
we'll be able to record a fix and emit a suitable
diagnostic.
2019-12-02 15:29:22 -08:00
Hamish Knight
aa8d7ba833 [CS] Apply all finishApply's transforms to callAsFunction
Rather than coercing the call arguments ourselves,
just build the finished member reference for the
callAsFunction method, and let finishApply do the
rest. This allows us to deal with transformations
such as IUO unwraps.

Resolves SR-11881.
2019-12-02 15:29:21 -08:00
Hamish Knight
bf0e9c727d [CS] Resolve callees for implicit callAsFunction
Add a case to getCalleeLocator to return the
appropriate locator for a call to an implicit
callAsFunction member reference.

Resolves SR-11386 & SR-11778.
2019-12-02 15:29:21 -08:00
Pavel Yaskevich
e09e8c3d72 [Diagnostics] NFC: Adjust diagnostics improved by extraneous arguments fix 2019-10-16 10:19:26 -07:00
Dan Zheng
f44064cbbc [SE-0253] Introduce callables. (#24299)
Introduce callables: values of types that declare `func callAsFunction`
methods can be called like functions. The call syntax is shorthand for
applying `func callAsFunction` methods.

```swift
struct Adder {
  var base: Int
  func callAsFunction(_ x: Int) -> Int {
    return x + base
  }
}
var adder = Adder(base: 3)
adder(10) // desugars to `adder.callAsFunction(10)`
```

`func callAsFunction` argument labels are required at call sites.
Multiple `func callAsFunction` methods on a single type are supported.
`mutating func callAsFunction` is supported.

SR-11378 tracks improving `callAsFunction` diagnostics.
2019-08-26 23:56:36 -07:00