Commit Graph

490 Commits

Author SHA1 Message Date
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
Pavel Yaskevich
17d46d13eb [Diagnostics] NFC: Make sure that requirement kind matches locator
When constructing requirement failures make sure that requirement
kind provided by the caller matches information about requirement
stored in the locator.
2018-10-24 18:20:27 -07:00
Pavel Yaskevich
70d9b2dfa3 [CSDiagnostics] Fix requirement source lookup to support initializers
Resolves: rdar://problem/45470505
2018-10-22 18:32:32 -07:00
gregomni
b7df1ca1df Re-try a failingConstraint during salvage now that attemptFixes is turned on. This enables better missing conforms-to diagnoses. 2018-10-13 20:06:19 -07:00
Pavel Yaskevich
27d0d26222 Revert "[CSDiagnostics] Don't mention special names in requirement diagnostics" 2018-09-21 14:44:04 -07:00
Pavel Yaskevich
02d5401499 [CSDiagnostics] Don't mention special names in requirement diagnostics
Instead of `initializer 'init' of ...` diagnostic should only
mention kind e.g. `initializer of ...` of the declaration
with a special name.
2018-09-21 00:35:21 -07:00
Pavel Yaskevich
bba7112506 [Diagnostics] NFC: Refactor assignment diagnostics into AssignmentFailure
Merge logic from `diagnoseAssignmentFailure` and `diagnoseSubElementFailure`
into new `AssignmentFailure`, together with their support functions, which
decouples `CSDiagnostics` from `CSDiag` and scrubs latter from some functionality.
2018-08-27 00:35:44 -07:00
Greg Titus
c95cfc6f69 Merge pull request #18950 from gregomni/rvalue-as-lvalue
[Diagnostics] Adding assignments directly to CS and diagnosing from there.
2018-08-26 11:12:57 -07:00
Pavel Yaskevich
7dda51bb81 [Diagnostics] Transform tryDiagnoseTrailingClosureAmbiguity into a failure 2018-08-25 00:19:41 -07:00
gregomni
821f63fe98 Make assignments and assignment failure diagnoses directly in the CS.
More specific diagnoses for assigning to read-only keypaths.
'computeAssignDestType' is dead code now.
ConstraintFix shouldRecordFix()
2018-08-24 20:39:03 -07:00
Pavel Yaskevich
294c05b41b [Diagnostics] Split FailureDiagnostic::diagnose(bool asNote) into diagnoseAs{Error, Note} 2018-08-24 12:19:52 -07:00
Pavel Yaskevich
eefbb1547c [Diagnostics] Implement diagnostic-as-note for requirement failures 2018-08-24 11:20:49 -07:00
Pavel Yaskevich
9f6891a4ed [Diagnostics] Add asNote flag to FailureDiagnostic
The flag is used to indicate that caller is interested in
diagnostic to be a note instead of an error, it's useful
when trying to diagnose ambiguities.
2018-08-24 11:20:49 -07:00
Pavel Yaskevich
cc436e313a [Diagnostics] Decouple FailureDiagnostic from Solution 2018-08-21 23:45:17 -07:00
Pavel Yaskevich
621204b7c6 Merge pull request #18870 from xedin/add-superclass-req-failure-diagnostic
[Diagnostics] Add `superclass` requirement fix/diagnostic
2018-08-21 09:16:41 -07:00
Pavel Yaskevich
16dfa6be72 [Diagnostics] Add superclass requirement fix/diagnostic
Extend new requirement failure diagnostics by adding "superclass"
generic requirement failures.
2018-08-21 00:39:21 -07:00
Greg Titus
e0a24ce93f Merge pull request #18827 from gregomni/rvalue-as-lvalue
[ConstraintSystem] Move more lvalue diagnostics over to being handled via ConstraintFix
2018-08-20 20:25:51 -07:00
gregomni
834b550c7c Instead of exposing getSolution, provide a restrictionForType API and use that. 2018-08-20 18:08:40 -07:00
gregomni
19fce5d36f Move another chunk of lvalue diagnostics over to being handled via ConstraintFix. 2018-08-19 13:14:55 -07:00
Pavel Yaskevich
3cc613497c [ConstraintSystem] Add same-type requirement fix/diagnostic
Extend new requirement failure diagnostics by adding "same-type"
generic requirement failures.
2018-08-18 13:05:32 -07:00
Greg Titus
32eacc5e80 Merge pull request #18608 from gregomni/rvalue-as-lvalue
[ConstraintSystem] New FailureDiagnostic for rvalues that should be lvalues
2018-08-18 11:43:23 -07:00
Pavel Yaskevich
6756c57f91 [Diagnostics] NFC: Move logic common to all requirement failures into RequirementFailure
This is going to make adding same-type and superclass requirement
failures might easier, because they only have to supply custom
diagnostic messages and substituted types.
2018-08-16 18:35:24 -07:00
gregomni
9e0dae513c Start changing over rvalue-vs-lvalue errors to be done via constraint system fixes. For this first commit, just handling inout parameter problems. 2018-08-16 17:34:17 -07:00
Pavel Yaskevich
0f411b1102 [Diagnostics] Extract requirement declaration context retrieval into its own method
Change logic to traverse the chain of declaration contexts
starting for "affected" declaration's parent and check if the
requirement is satisfied by one of them, if so return it as
requirement's declaration context.

Extract this logic into a method on `RequirementFailure` to make
it accessible for other types of requirement failure diagnostics.
2018-08-16 01:25:51 -07:00
Pavel Yaskevich
e631a37ef6 [ConstraintSystem] Replace Fix with ConstraintFix throughout solver 2018-08-13 18:10:27 -07:00
Pavel Yaskevich
6d64b1c8a5 [Diagnostics] Some diagnostics possible only when locator is resolved down to expression 2018-08-09 22:23:31 -07:00
Pavel Yaskevich
e2cde5acc2 [Diagnostics] Port 'missing optional unwrap' diagnostic to new abstraction 2018-08-09 17:47:06 -07:00
Pavel Yaskevich
d72c204bad [Diagnostics] Port member access on optional base diagnostic to new abstraction 2018-08-09 17:03:20 -07:00
Pavel Yaskevich
a564042fdc [Diagnostics] Port missing explicit conversion to new abstraction 2018-08-09 17:01:54 -07:00
Pavel Yaskevich
9f9904b65d [Diagnostics] Port missing & diagnostic to new abstraction 2018-08-09 13:57:57 -07:00
Pavel Yaskevich
284e109f1e [Diagnostics] Try to compute precise diagnostic anchor 2018-08-09 13:53:33 -07:00
Pavel Yaskevich
f5aa0d9c75 [Diagnostics] Port missing force downcast diagnostic to new abstraction 2018-08-09 11:56:19 -07:00
Pavel Yaskevich
157dc719e0 [Diagnostics] Port implicitly escaping to type conversion diagnostics to new abstraction 2018-08-09 11:05:33 -07:00
Pavel Yaskevich
776485878f [ConstraintSystem] NFC: Move new diagnostics into separate files - Diagnostics.(h|cpp) 2018-08-06 13:08:47 -07:00