Commit Graph

1160 Commits

Author SHA1 Message Date
Luciano Almeida
697b407589 Fixing test on test/Generics/conditional_conformances.swift 2019-10-12 18:20:23 -03:00
Luciano Almeida
05cea3a7b7 Fix issue with dictionary_downcast tests 2019-10-12 16:49:36 -03:00
Luciano Almeida
f39ff88113 Initial implementation of moving the checks 2019-10-12 15:22:16 -03:00
Luciano Almeida
21c179d46f Removing fixed CoerceToCheckedCast constraint and letting repairFailures handle the diagnostics 2019-10-12 11:38:59 -03:00
Luciano Almeida
12f98d7922 Merge branch 'master' into force-downcast-fix-explicit-coercion 2019-10-06 13:35:44 -03:00
Hamish Knight
c108dae5d9 [CSDiagnostics] Find argument lists for key path subscripts
This commit changes `getArgumentExprFor` to take
a ConstraintLocator argument from which to find
the argument list. This lets us properly handle
the case where we have a key path subscript
locator. In addition, this commit renames the
member to `getArgumentListExprFor` to make it
clear we're returning the argument list expression
rather than a single argument.

Resolves SR-11562.
2019-10-02 08:00:14 -07:00
Luciano Almeida
c01688f93f Fixing nit formatting 2019-10-02 07:30:17 -03:00
Luciano Almeida
980ff05972 Add ForceDownCast fix for coercion expr to avoid fall-through into CSDiag 2019-10-01 20:25:15 -03:00
Hamish Knight
6d8b798789 [CS] Have isLastElement take a locator path elt class
This makes it consistent with `getLastElementAs`
and `castLastElementTo`.
2019-09-29 14:19:56 -07:00
Pavel Yaskevich
6aadbc3d52 Merge pull request #27390 from xedin/sr-11491
[Diagnostics] Centralize requirement failure impact assessment
2019-09-27 19:39:36 -07:00
Pavel Yaskevich
24a5003078 [ConstraintSystem] Materialize locator only once per missing argument
Instead of materializing locator twice from the same builder per
missing argument, do it only once and use result to create argument
type variable and its "defaults to Any" constraint.
2019-09-26 20:48:49 -07:00
Pavel Yaskevich
694023ac7c [Diagnostics] Centralize requirement failure impact assessment
Conformance requirements get their fixes attached directly where
other requirements have to use (for now) `repairFailure` mechanism.

Regardless of _how_ fixes get recorded there should be a single
way to assess impact of a particular requirement failure.

The rules are:

- If this is a requirement associated with an operator, impact
  is based on use of the type which failed the requirement;

- If this requirement is from conditional extension,
  it is considered a very high impact because failing such
  requirement makes referenced member de facto invisible.

Resolves: rdar://problem/55593998
Resolves: [SR-11491](https://bugs.swift.org/browse/SR-11491)
2019-09-26 12:13:06 -07:00
Pavel Yaskevich
10b1baebb2 Merge pull request #27362 from xedin/port-missing-args
[Diagnostics] Port missing argument(s) diagnostics
2019-09-25 21:08:54 -07:00
Slava Pestov
b1ffa19c7b AST: Refine recursive property checks on type alias types 2019-09-24 17:39:53 -04:00
Pavel Yaskevich
a3e26abd8a [ConstraintSystem] Mark each of the synthesized arguments as a "hole" 2019-09-24 11:00:57 -07:00
Robert Widmann
3e48f71b27 Merge pull request #27314 from CodaFi/an-interface-to-the-interface
Requestify getInterfaceType() in Name Only
2019-09-23 22:35:24 -07:00
Robert Widmann
f053f9c480 Port getInterfaceType() patterns in libSema 2019-09-23 16:49:29 -07:00
Pavel Yaskevich
73b6427f64 [ConstraintSystem] Store parameter flags in synthesized argument locator 2019-09-23 14:19:29 -07:00
Pavel Yaskevich
ee8c78eef5 [Diagnostics] Tailored diagnostic when single tuple used instead of N distinct arguments
Diagnose cases when instead of multiple distinct arguments
call got a single tuple argument with expected arity/types:

```swift
func foo(_: Int, _: Int) {}
foo((0, 1)) // expected 2 arguments, got 1 tuple with 2 elements
```
2019-09-23 13:00:37 -07:00
Pavel Yaskevich
b8528cd575 [ConstraintSystem] Short-circuit matching if missing arguments have been synthesized 2019-09-23 13:00:37 -07:00
Pavel Yaskevich
65c03d5f06 [ConstraintSystem] Allow solver to synthesize missing arguments in diagnostic mode 2019-09-23 13:00:37 -07:00
Pavel Yaskevich
b15ef15a60 [ConstraintSystem] Change missingArgument callback to produce an index of synthesized argument
In diagnostic mode allow argument matcher to synthesize new
arguments, which makes it much easier to diagnose problems
related to missing arguments.
2019-09-23 12:59:27 -07:00
Pavel Yaskevich
96598d8ebf Merge pull request #26207 from owenv/new-vararg-conversion-diag
[Diagnostics] Improve diagnostic when attempting to pass an Array to a variadic argument
2019-09-23 12:57:44 -07:00
Robert Widmann
b135928125 Drop CheckingWithValidSignature from the validation state machine
Now that the generic signature is computable on demand, this predicate is doubly useless.  All of the callers intended to ask "hasInterfaceType" anyways.
2019-09-20 22:22:49 -07:00
Owen Voorhees
6c5185f2e3 Improve diagnostic when attempting to pass an Array to a variadic argument
- Give a more specific diagnostic which indicates the parameter is variadic
- If the argument is an Array literal, offer to drop the brackets
2019-09-20 17:30:23 -07:00
Pavel Yaskevich
8eaeb51fe5 [ConstraintSystem] Introduce a fix for assignment type mismatch
Introduce a fix/diagnostic when there is a contextual mismatch
between source and destination types of the assignment e.g.:

```swift
var x: Int = 0
x = 4.0 // destination expects an `Int`, but source is a `Double`
```
2019-09-20 17:12:04 -07:00
Pavel Yaskevich
c968c14a24 [Diagnostics] Cover single explicit tuple argument -> N parameters via missing arguments fix
Expand tuple into N arguments to cover expect parameters.

This covers cases like this:

```swift
func foo(_: (Int, Int) -> Void) {}
foo { (bar: (Int, Int)) in } // used a single tuple type `(Int, Int)`
                             // instead of two distinct arguments
```
2019-09-17 00:27:17 -07:00
Pavel Yaskevich
2f325fa1d8 [Diagnostics] Don't store contextual type in missing argument fix/diagnostic
Instead of storing contextual function type in the fix/diagnostic,
let's fetch it from context (solution and/or locator) because it's
only used when it is a trailing closure missing some arguments anyway.
2019-09-16 16:50:31 -07:00
Pavel Yaskevich
1cd1f259e0 [ConstraintSystem] NFC: Fix typo implact -> impact 2019-09-13 22:35:53 -07:00
Pavel Yaskevich
afc3408b60 [ConstraintSystem] De-prioritize missing member fix when base is contextual
Impact is higher if the base is expected to be inferred from context,
because a failure to find a member ultimately means that base type is
not a match in this case.
2019-09-13 22:35:53 -07:00
Pavel Yaskevich
c20e4ac3c2 [Diagnostics] Fix usages of getChoiceFor 2019-09-13 22:35:53 -07:00
Pavel Yaskevich
26e51e0e43 [ConstraintSystem] Fix: Try to match argument to element type if parameter is a collection
This allows better diagnostics in cases where collection element
is a generic parameter which is supposed to be inferred from argument e.g.

```swift
func foo<T>(_: [T]) {}

foo(1) // Missing brackets, so error should be about [Int] vs. Int
```
2019-09-13 22:35:53 -07:00
Pavel Yaskevich
b0299f7066 [CSSimplify] NFC: Adjust comment about matching dependent types with invalid base 2019-09-13 22:35:53 -07:00
Pavel Yaskevich
b898eaf326 [Diagnostics] Tailored diagnostics for reference equality operator mismatches 2019-09-13 22:35:52 -07:00
Pavel Yaskevich
25d7a07323 [ConstraintSystem] Adjust a couple of places not to fail immediately in diagnostic mode
Some spots of constraint simplification logic are too eager to
fail right away without giving repair logic to run in diagnostic
mode and attempt to fix the problem. Failing early in diagnostic
mode means solver wouldn't be able to reach some possible
solutions which leads to subpar diagnostics.
2019-09-13 22:35:52 -07:00
Pavel Yaskevich
df8d1a078a [ConstraintSystem] Fail comparison if dependent member types couldn't be resolved
Currently in cases where dependent member types cannot be resolved
properly due to invalid base type they do not fail comparison, but
instead result in a new "inactive" constraint which is incorrect.
2019-09-13 22:35:52 -07:00
Pavel Yaskevich
015129cb36 [Diagnostics] Allow requirement failure to diagnose operators
In absence of general argument conversion failures requirement
errors associated with operators couldn't be diagnosed properly,
now this restriction could be lifted.
2019-09-13 22:35:51 -07:00
Pavel Yaskevich
79606619a7 [ConstraintSystem] Lift restriction which restricted conformance fixes in argument positions
If argument doesn't conform to the protocol expected by the parameter
let's add argument conversion mismatch fix for that with increased impact.
2019-09-13 22:35:50 -07:00
Pavel Yaskevich
446d0f84f4 [ConstraintSystem] Rate impact of conformance failures based on non-conforming type use
Impact of conformance failure should be rated based on use of
associated generic parameter, because a single failure could
span multiple parameters and a result.

Originally score was only increased once for conformance failure.
That is not good enough in cases when conformance is associated
with an overload choice, because in that case we can have an argument
mismatch in other choice which would have the same score impact.
2019-09-13 22:35:50 -07:00
Pavel Yaskevich
953b9f74aa [ConstraintSystem] Fix a situation when argument requires raw representable type 2019-09-13 22:35:50 -07:00
Pavel Yaskevich
c946b3862e [ConstraintSystem] Don't produce argument mismatch fix when pointer conversions are involved 2019-09-13 22:35:50 -07:00
Pavel Yaskevich
93b39c9c23 [Diagnostics] Port pattern-matching mismatch diagnostic
Port diagnostics associated with implicit use of `~=` operator
which is used in `case` statements.
2019-09-13 22:35:50 -07:00
Pavel Yaskevich
1a57fc403a [ConstraintSystem] Make sure that l-value is preserved in argument positions
There is logic in `matchTypes` which would unwrap l-value if other
type is not an `inout`, which is not great for cases where parameter
type is a pointer and argument is an l-value which requires explicit
`&` to be converted.
2019-09-13 22:35:50 -07:00
Pavel Yaskevich
65c966ba16 [Diagnostics] Port a custom diagnostic for archetype mismatch in argument position 2019-09-13 22:35:50 -07:00
Pavel Yaskevich
9d84aab2d5 [ConstraintSystem] Score generic argument-to-parameter mismatch fixes down
Since this is the most generic failure, we need to make sure that
it doesn't interfere with other more specific fixes.
2019-09-13 22:35:50 -07:00
Pavel Yaskevich
f28e674395 [Diagnostics] Detect situation when argument would match if it wasn't optional 2019-09-13 22:35:50 -07:00
Pavel Yaskevich
0f24f7e05a [CSFix] Introduce a fix for argument-to-parameter conversion mismatch 2019-09-13 22:35:50 -07:00
Sasha Krassovsky
8cae17ceac Fix warnings in Sema 2019-09-13 09:57:48 -07:00
Slava Pestov
cd8fddd2df Merge pull request #27145 from slavapestov/refactor-type-check-checked-cast
Refactor typeCheckCheckedCast() and a few other things
2019-09-12 21:07:07 -04:00
Holly Borla
0434d58ff0 Merge pull request #27123 from hborla/missing-conformance-diag
[ConstraintSystem] Allow fixing missing conformance failures for `Void` and uninhabited types.
2019-09-12 17:41:19 -07:00