Commit Graph

483 Commits

Author SHA1 Message Date
Pavel Yaskevich
b9a0ca6afb [ConstraintSystem] Detect and diagnose conversion failures related to collection element types
Detect and diagnose a contextual mismatch between expected
collection element type and the one provided (e.g. source
of the assignment or argument to a call) e.g.:

```swift
let _: [Int] = ["hello"]

func foo(_: [Int]) {}
foo(["hello"])
```
2019-05-14 17:33:11 -07:00
Sam Lazarus
2309ee580a Merge pull request #24617 from sl/sl/sr-10297
Add a Diagnostic for .init calls which should be transformed into assignments (SR-10297)
2019-05-09 18:05:38 -04:00
Sam Lazarus
c498f38e5f Sema: Changed name of isInsideCall to isCallArgument and formatted changes 2019-05-08 23:44:29 -04:00
Sam Lazarus
edd8f70330 Sema: Change the diagnostic to choices made by the constraint system 2019-05-08 23:37:51 -04:00
Slava Pestov
b6985acc23 Sema: More flexible InvalidUseOfAddressOf 2019-05-07 23:10:48 -04:00
Pavel Yaskevich
4f63c4af71 [ConstraintSystem] Detect and diagnose extraneous returns from void functions
Diagnose an attempt return something from a function which
doesn't have a return type specified e.g.

```swift
func foo() { return 42 }
```
2019-05-07 13:43:14 -07:00
Pavel Yaskevich
6cd476be47 Merge pull request #24522 from xedin/diag-extraneous-addr-of
[ConstraintSystem] Detect and fix extraneous use of `&`
2019-05-06 13:56:04 -07:00
Pavel Yaskevich
3af163a94c [ConstraintSystem] Detect and fix extraneous use of &
Diagnose extraneous use of address of (`&`) which could only be
associated with arguments to `inout` parameters e.g.

```swift
struct S {}

var a: S = ...
var b: S = ...

a = &b
```
2019-05-06 11:18:47 -07:00
Sam Lazarus
4fac0b31c8 Merge pull request #24450 from sl/sl/sr-10202
Add useful diagnostic when trying to write through key path on private(set) var
2019-05-06 13:09:22 -04:00
Pavel Yaskevich
43526d031c Merge pull request #24431 from xedin/diag-noescape-param-assignment
[ConstraintSystem] Improve @escaping parameter diagnostics
2019-05-04 20:09:31 -07:00
Sam Lazarus
1d22e987c8 Sema: Add a diagnostic for assigning using a subscript with a read-only keypath 2019-05-03 22:16:56 -04:00
Pavel Yaskevich
21216d8ecd [ConstraintSystem] Detect and fix invalid refs in dynamic key path member lookup
KeyPath dynamic member lookup is limited to what key path itself
could do, so let's detect and diagnose invalid references just
like we do for regular key path expressions.

Resolves: rdar://problem/50376224
2019-05-02 15:02:11 -07:00
Pavel Yaskevich
62b2da803c [ConstraintSystem] Improve @escaping parameter diagnostics
Detect difference in escapiness while matching function types
in the solver and record a fix that suggests to add @escaping
attribute where appropriate.

Also emit a tailored diagnostic when non-escaping parameter
type is used as a type of a generic parameter.
2019-05-02 00:40:30 -07:00
Pavel Yaskevich
6fdb5482d4 [Diagnostics] Diagnose invalid method references in key path 2019-04-22 16:40:14 -07:00
Pavel Yaskevich
eaf1dc0012 [Diagnostics] Diagnose use of member with mutating getter in key path 2019-04-17 11:51:33 -07:00
Pavel Yaskevich
c33b726486 [Diagnostics] Extract logic common to all key path invalid ref diagnostics 2019-04-17 11:34:13 -07:00
Pavel Yaskevich
55bc16e785 [Diagnostics] Diagnose static member reference as a key path component 2019-04-15 23:42:34 -07:00
Suyash Srijan
072e84acd6 [CSSimplify] Reject key path if root type is AnyObject (#23820)
Detect situations where `AnyObject` is attempted to be used as a root type of the key path
early and diagnose via new diagnostics framework.
2019-04-14 12:18:35 -07:00
Pavel Yaskevich
439335ddb0 [Diagnostics] Extend keypath subscript index missing Hashable to support dynamic member lookup 2019-04-10 15:10:47 -07:00
Pavel Yaskevich
c3460f825d [Diagnostics] Diagnose keypath subscript components with missing Hashable conformances 2019-04-10 13:51:12 -07:00
Pavel Yaskevich
dd810a7b24 [Diagnostics] Improve mutability diagnostics related to dynamic member lookup
Since there is a way to mutate through use of writable keypath
diagnostics have to be adjusted to point to the members found
via keypath member lookup instead to using catch-all
"immutable base" diagnostic.
2019-04-01 12:41:55 -07:00
Suyash Srijan
56b0c55dfb [cs] make tryComputedPropertyFixIts() a private instance method 2019-03-25 01:33:41 +00:00
Suyash Srijan
5a8e1fa955 [cs] extract computed property fix-it into separate method 2019-03-25 00:07:41 +00:00
Pavel Yaskevich
688042becf [Diagnostics] Add inaccessible member diagnostic 2019-03-18 13:48:08 -07:00
Pavel Yaskevich
3940cebebf [Diagnostics] Don't suggest unwrap with default value if type is not materializable 2019-03-08 01:07:54 -08:00
Pavel Yaskevich
39dd6306c6 [Diagnostics] Refactor missing optional unwrap diagnostic
Instead of passing all of the information available in the diagnostic
to static functions, let's bring "default value" and "force unwrap"
fix-it logic under "missing optional unwrap diagnostic" umbrella.
2019-03-07 15:39:42 -08:00
Pavel Yaskevich
2e14bec250 [Diagnostics] Add out-of-order argument diagnostic 2019-03-04 20:03:54 -08:00
Pavel Yaskevich
9999a47197 [Diagnostics] Add closure parameter destructuring diagnostic 2019-03-04 11:37:43 -08:00
Pavel Yaskevich
aeaa26d926 [CSDiagnostics] Add missing arguments failure
Currently only supports closures, but could be easily expanded
to other types of situations e.g. function/member calls.
2019-02-26 13:29:35 -08:00
Suyash Srijan
34f8670d2a [CS] Use fixes to diagnose instance member on type (or vice versa) access (#21830)
This PR migrates instance member on type and type member on instance diagnostics handling to use the new diagnostics framework (fixes) and create more reliable and accurate diagnostics in such scenarios.
2019-02-22 16:57:26 -08:00
Pavel Yaskevich
d4b67bf3f7 [Diagnostics] Improve argument labeling diagnostics
Extend new labeling diagnostics (via fixes) to support
member references and subscripts.
2019-02-21 16:42:56 -08:00
Pavel Yaskevich
a7c66ca476 [CSDiagnostics] Imporove requirement diagnostics originating in contextual type
Detect that failed requirement comes from contextual type and use
that information to determine affected declaration.

Resolves: rdar://problem/47980354
2019-02-18 17:58:28 -08:00
Pavel Yaskevich
70b5bce791 [CSFix] Use fully qualified locators for requirement failures
Would help to diagnose failures where requirement comes from
contextual type, also simplifies logic around requirement fixes
to some degree.
2019-02-18 12:03:46 -08:00
Pavel Yaskevich
4f0f090e36 [CSDiagnostics] Use generic signature to retrieve failing requirement 2019-02-14 12:18:17 -08:00
Pavel Yaskevich
75b5824bf9 Merge pull request #22480 from xedin/rdar-47871590
[ConstraintSystem] Diagnose conditional requirement failures via fixes
2019-02-11 14:58:08 -08:00
Pavel Yaskevich
42e0f21409 [CSDiagnostics] Improve requirement failure source detection
If affected declaration is a static or instance memeber (excluding
operators) and failed requirement is declared in other nominal type
or extension, diagnose such problems as `in reference` instead of
claiming that requirement belongs to the member itself.
2019-02-08 15:05:42 -08:00
Pavel Yaskevich
0d0c132ecd [Sema] NFC: Add accessors to check whether locator is type or conditional requirement 2019-02-08 15:04:44 -08:00
Pavel Yaskevich
dfac0d8323 [CSDiagnostics] Augment RequirementFailure to support conditional requirements 2019-02-08 11:14:41 -08:00
Pavel Yaskevich
1d42e16ad2 [ConstraintSystem] Detect invalid implicit ref to initializer on non-const metatype
Situations like:

```swift
struct S {}
func foo(_ s: S.Type) {
  _ = s()
}
```

Used to be diagnosed in solution application phase, which means that
solver was allowed to formed an incorrect solution.
2019-02-07 00:17:07 -08:00
Pavel Yaskevich
0595cefab3 [CSDiagnostics] Add diagnostics for two kinds of incorrect initializer reference
- Attempting to construct class object using metatype value via
  non-required initializer

- Referencing initializer of protocol metatype base

Both of the diagnostics are used by `AllowInvalidInitRef` fix.
2019-02-05 10:28:41 -08:00
Pavel Yaskevich
462cb1ffb1 Merge pull request #22124 from xedin/diagnose-partial-applies
[CSDiagnostics] Diagnose invalid partial application
2019-01-28 10:44:56 -08:00
Pavel Yaskevich
1c79380a12 [CSFix] Couple of small cleanups related to ForceOptional
* Make sure that base and unwrapped types aren't null
* Don't allocate `ForceOptional` fix if nothing has been unwrapped
  in `simplifyApplicableFnConstraint`
* Add sugar reconstitution support to `FailureDiagnostic::resolveType`
* Format diagnostics a bit better
2019-01-26 00:48:01 -08:00
Pavel Yaskevich
315a0adc93 [CSDiagnostics] Add invalid partial apply diagnostic for mutating methods 2019-01-25 14:17:54 -08:00
Suyash Srijan
76b8209b25 [cs] store base type and unwrapped type in the fix 2019-01-25 10:13:37 +00:00
Pavel Yaskevich
74a8ee177e [Diagnostics] Diagnose missing members via fixes
Try to fix constraint system in a way where member
reference is going to be defined in terms of its use,
which makes it seem like parameters match arguments
exactly. Such helps to produce solutions and diagnose
failures related to missing members precisely.

These changes would be further extended to diagnose use
of unavailable members and other structural member failures.

Resolves: rdar://problem/34583132
Resolves: rdar://problem/36989788
Resolved: rdar://problem/39586166
Resolves: rdar://problem/40537782
Resolves: rdar://problem/46211109
2019-01-09 17:29:49 -08:00
Pavel Yaskevich
06a7ad63f8 [Diagnostics] Diagnose subscript operator misuse via fixes
Fix to use subscript operator instead of spelled out name helps
to produce a solution, that makes it much easier to diagnose
problems precisely and provide proper fix-its, it also helps to
diagnose ambiguous cases, and stacks up nicely with other errors.
2019-01-08 12:06:40 -08:00
Pavel Yaskevich
9818b55266 [CSDiagnostics] Add MissingCall failure
It's used to diagnose cases when function/method are used as
a property instead of being called.
2018-12-11 18:44:41 -08:00
Pavel Yaskevich
202234f325 [CSDiagnostics] Diagnose invalid optional unwrap via fixes
Detect and fix situations when (force) unwrap is used on
a non-optional type, this helps to diagnose invalid unwraps
precisely and provide fix-its.

Resolves: [SR-8977](https://bugs.swift.org/browse/SR-8977)
Resolves: rdar://problem/45218255
2018-12-05 08:10:07 -08:00
Pavel Yaskevich
07e5d54855 [CSDiagnostics] Add custom diagnostic for invalid @autoclosure forwarding
Suggest to add `()` (form a call) to correctly forward argument function
originated from `@autoclosure` parameter to function parameter itself
marked as `@autoclosure`.
2018-11-21 12:17:25 -08:00
Pavel Yaskevich
66a79301b4 [CSDiagnostics] Diagnose contextual closure result mismatches via fixes
Let's keep track of type mismatch between type deduced
for the body of the closure vs. what is requested
contextually, it makes it much easier to diagnose
problems like:

```swift
func foo(_: () -> Int) {}
foo { "hello" }
```

Because we can pin-point problematic area of the source
when the rest of the system is consistent.

Resolves: rdar://problem/40537960
2018-11-07 14:28:50 -08:00