Commit Graph

1245 Commits

Author SHA1 Message Date
gregomni
8d70f980b3 Offer a "self." fixit for assigning to a let which is masking an instance variable. 2018-09-19 20:20:45 -07:00
Pavel Yaskevich
882875eb66 [CSDiagnostics] Fix requirement source lookup to support subscripts
Resolves: rdar://problem/44569159
2018-09-18 14:48:41 -07:00
Saleem Abdulrasool
d281b98220 litter the tree with llvm_unreachable
This silences the instances of the warning from Visual Studio about not all
codepaths returning a value.  This makes the output more readable and less
likely to lose useful warnings.  NFC.
2018-09-13 15:26:14 -07:00
gregomni
13d02bb85c Make the rvalue-as-lvalue fix symmetric for bind constraints, which causes another set of assignment errors to be discovered in
the CS and slightly reduces the code in CSDiag.
2018-08-29 19:07:29 -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
c69097f027 Merge pull request #18980 from xedin/move-salvage-to-cs
[ConstraintSystem] Move `salvage` and related logic away from `CSDiag`
2018-08-25 14:09:48 -07:00
Robert Widmann
661c30f93e Merge pull request #18963 from CodaFi/its-not-unusual-to-be-unused-by-anyone
[NFC] Silence a bunch of Wunused-variable diagnostics
2018-08-25 09:24:44 -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
Robert Widmann
014fd952ef [NFC] Silence a bunch of Wunused-variable diagnostics 2018-08-24 15:16:40 -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
16fc3117cc [ConstraintSystem] Diagnose ambiguities related to solutions with fixes
If all of the solutions in the set have a single fix, which points
to the common anchor, attempt to diagnose the failure as an
ambiguity with a list of candidates and their related problems as notes.

Having richer message like that helps to understand why something is
ambiguous e.g. if there are two overloads, one requires conformance
to some protocol and another has a same-type requirement on some type,
but neither matched exactly, having both candidates in the diagnostic
message with associated errors, instead of simplify pointing to related
declarations, helps tremendously.
2018-08-24 11:20:49 -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
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
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
gregomni
aeb96274d2 Apply the solution to the CS before diagnosing solution fixes. 2018-08-18 08:38:16 -07:00
Pavel Yaskevich
5c27ea0d07 Merge pull request #18813 from xedin/switch-to-use-generic-signature-of-context
[Diagnostics] NFC: refactor `getRequirementDC` to use `getGenericSign…
2018-08-17 21:22:42 -07:00
Pavel Yaskevich
e1ad3079b6 [Diagnostics] NFC: refactor getRequirementDC to use getGenericSignatureOfContext 2018-08-17 18:52:24 -07:00
Jordan Rose
537954fb93 [AST] Rename several DeclContext methods to be clearer and shorter (#18798)
- getAsDeclOrDeclExtensionContext -> getAsDecl

This is basically the same as a dyn_cast, so it should use a 'getAs'
name like TypeBase does.

- getAsNominalTypeOrNominalTypeExtensionContext -> getSelfNominalTypeDecl
- getAsClassOrClassExtensionContext -> getSelfClassDecl
- getAsEnumOrEnumExtensionContext -> getSelfEnumDecl
- getAsStructOrStructExtensionContext -> getSelfStructDecl
- getAsProtocolOrProtocolExtensionContext -> getSelfProtocolDecl
- getAsTypeOrTypeExtensionContext -> getSelfTypeDecl (private)

These do /not/ return some form of 'this'; instead, they get the
extended types when 'this' is an extension. They started off life with
'is' names, which makes sense, but changed to this at some point.  The
names I went with match up with getSelfInterfaceType and
getSelfTypeInContext, even though strictly speaking they're closer to
what getDeclaredInterfaceType does. But it didn't seem right to claim
that an extension "declares" the ClassDecl here.

- getAsProtocolExtensionContext -> getExtendedProtocolDecl

Like the above, this didn't return the ExtensionDecl; it returned its
extended type.

This entire commit is a mechanical change: find-and-replace, followed
by manual reformatted but no code changes.
2018-08-17 14:05:24 -07:00
gregomni
44ce96a040 Want to directly use the locator anchor for RValueTreatedAsLValueFailure::diagnose() rather than the computed anchor. Assorted other cleanup, comment improvement. 2018-08-16 21:15:17 -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
fc4137052d Merge pull request #18752 from xedin/add-get-req-dc-to-failure
[Diagnostics] Extract requirement declaration context retrieval into …
2018-08-16 13:28:20 -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
gregomni
4d862d50cb In tryTypeVariableBindings, if T? fails, try T for all binding kinds (previously just allowed for Subtypes). This allows us to always find MissingOptionalUnwrapFailures, so that all the unwrap fixit code can be moved into CSDiagnostics and made static. 2018-08-14 09:14:59 -07:00
Greg Titus
8f41ee7750 Merge pull request #18324 from gregomni/opty2
[Sema] More unwrap fixits
2018-08-14 09:12:35 -07:00
Slava Pestov
31a570d53c AST: Replace TypeBase::getRValueInstanceType() with getMetatypeInstanceType()
That is, don't look through InOutType anymore, and update callers to
call getInOutObjectType() as well (or not, where it was obvious to me
that InOutType could not appear).

This surfaces more remaining uses of getInOutObjectType() directly.
2018-08-13 21:13:10 -07:00
Pavel Yaskevich
3c7d7782db [Diagnostics] Don't try to diagnose missing conformance for any type of operator call
My original diagnostic changes included only `BinaryExpr` but there
are also postfix/prefix that I missed.
2018-08-13 18:06:49 -07:00
gregomni
ba96db66de Conflict resolution. 2018-08-12 12:57:20 -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
ba085e5bdc [Diagnostics] Improve missing conformance diagnostics for sub-types and members
If generic parameter associated with missing conformance comes
from different context diagnose the problem as "referencing" a
specific declaration from affected type.
2018-08-07 18:55:43 -07:00
Pavel Yaskevich
ad171e05cc [Diagnostics] Improve missing conformance diagnostics by using affected declaration
Instead of simply pointing out which type had conformance failures,
let's use affected declaration instead, which makes diagnostics much
richer e.g.

```
'List<[S], S.Id>' requires that 'S.Id' conform to 'Hashable'
```

versus

```
initializer 'init(_🆔)' requires that 'E' conform to 'Hashable' [with 'E' = 'S.Id']
```

Since latter message uses information about declaration, it can also
point to it in the source. That makes is much easier to understand when
problem is related to overloaded (function) declarations.
2018-08-07 12:59:53 -07:00
Pavel Yaskevich
776485878f [ConstraintSystem] NFC: Move new diagnostics into separate files - Diagnostics.(h|cpp) 2018-08-06 13:08:47 -07:00