Commit Graph

1183 Commits

Author SHA1 Message Date
Pavel Yaskevich
b009bf6154 Merge pull request #22630 from xedin/add-generic-context-to-locator
[ConstraintLocator] Add generic signature to `OpenedGeneric` element
2019-02-15 17:36:19 -08:00
Pavel Yaskevich
4f0f090e36 [CSDiagnostics] Use generic signature to retrieve failing requirement 2019-02-14 12:18:17 -08:00
Parker Schuh
b12fcb50db IntegerLiteralExpr now is lowered directly into SIL.
For context, String, Nil, and Bool already behave this way.

Note: Before it used to construct (call, ... (integer_literal)), and the
call would be made explicit / implicit based on if you did eg: Int(3) or
just 3. This however did not translate to the new world so this PR adds
a IsExplicitConversion bit to NumberLiteralExpr. Some side results of
all this are that some warnings changed a little and some instructions are
emitted in a different order.
2019-02-14 11:54:16 -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
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
174fd14090 [CSDiagnostics] Diagnose invalid partial application of init delegation 2019-01-25 14:18:04 -08:00
Pavel Yaskevich
315a0adc93 [CSDiagnostics] Add invalid partial apply diagnostic for mutating methods 2019-01-25 14:17:54 -08:00
Suyash Srijan
6a0a1dec05 [cs] use anchor instead of locator, etc 2019-01-25 21:36:07 +00:00
Suyash Srijan
76b8209b25 [cs] store base type and unwrapped type in the fix 2019-01-25 10:13:37 +00:00
Suyash Srijan
f5264b9779 [diag] fix incorrect diagnostic when unwrapping double optional 2019-01-22 22:03:40 +00:00
Slava Pestov
81c5a67489 Merge pull request #21758 from pschuh/s-1
Rename NameAliasType to TypeAliasType.
2019-01-10 15:20:41 -05: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
Parker Schuh
f5859ff46e Rename NameAliasType to TypeAliasType. 2019-01-09 16:47:13 -08:00
Pavel Yaskevich
91e97a0c8f [Diagnostics] Diagnose ambiguity resulting from subscript operator fix as a missing member
Since the rule is to prioritize names over types, let's diagnose
ambiguous solutions containing subscript operator fix as missing
member and list possible candidates to use.
2019-01-08 12:09:02 -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
03d283171c [CSDiagnostics] Fix requirement source lookup to support member references
Fuzzing found a problem related to re-typecheck introducing
`MemeberRefExpr` into AST with failing requirements which
are then diagnosted via fixes, quite unlikely case to be
found in the wild.
2018-11-30 13:48:19 -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
Mark Lacey
018498fb2f Merge pull request #16942 from bjhomer/bjhomer/optional-try-flattening
Flatten nested optionals resulting from try? and optional sub-expressions
2018-11-16 11:14:05 -08:00
Dan Zheng
2863b6cc64 Gardening for @dynamicMemberLookup. (#20498)
* Gardening for `@dynamicMemberLookup`.

- Unify code style of `@dynamicMemberLookup` and `@dynamicCallable` implementations.
  - Use consistent variable names, diagnostic messages, doc comments, etc.
- Move `@dynamicMemberLookup` test to `test/attr` directory.
2018-11-11 21:54:19 -05: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
BJ Homer
1789d44d6c Don't consider fixups that won't do anything.
Since 'try?' no longer unconditionally adds a layer of optional, converting it
to 'try!' will no longer unconditionally remove a layer of optional. So let's not
suggest it. This leads to better diagnostics anyway.
2018-11-06 23:31:02 -07:00
Pavel Yaskevich
a01a70f671 [CSDiagnostics] Fix requirement source lookup to support unresolved members
Resolves: rdar://problem/45692538
2018-10-31 00:06:15 -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
Slava Pestov
2d4b25960d Sema: Type variables for opened generic parameters store the generic parameter type and not an archetype
There's no need to instantiate archetypes in the generic environment
of the declaration being opened.

A couple of diagnostics changed. They were already misleading, and the
new diagnostics, while different, are not any more misleading than
before.
2018-09-27 20:49:23 -07:00
Slava Pestov
3b60ae153d AST: Rename AnyFunctionType::Param::getType() to getOldType() 2018-09-26 11:05:23 -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
6dc4591a5f Merge pull request #19447 from xedin/fix-req-diagnstics-not-to-print-special-names
[CSDiagnostics] Don't mention special names in requirement diagnostics
2018-09-21 14:17:08 -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
gregomni
ffc4f66448 A better note message. 2018-09-20 11:59:35 -07:00
gregomni
b613f130e7 Review feedback - mostly a better error message. 2018-09-20 09:05:30 -07:00
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