Commit Graph

152 Commits

Author SHA1 Message Date
Doug Gregor
bc926f7eb7 [Constraint system] Drop the root expression from FailureDiagnostic.
We're not using it for anything, now.
2019-11-08 22:38:49 -08:00
Robert Widmann
7b9d28d7ba Make diagnoseSelfAssignment a utility 2019-11-06 15:08:59 -08:00
Pavel Yaskevich
30440d8235 [Diagnostics] Properly diagnose assignment mismatch in ambiguity cases 2019-11-05 12:38:13 -08:00
Pavel Yaskevich
7cd7cd43e6 [Diagnostics] Port self assignment diagnostic to the new framework 2019-11-05 12:38:13 -08:00
Holly Borla
e840d52258 [Diagnostics] Allow fixes with the same locator to be coalesced before
application rather than throwing away subsequent fixes.

The "primary fix" decides whether or not to coalesce fixes that have
the same locator.
2019-11-05 09:15:13 -08:00
Hamish Knight
65dda6d945 Address other review feedback 2019-11-03 08:42:26 -08:00
Hamish Knight
7077a68b83 [Sema] Diagnose unsound pointer conversions
Diagnose ephemeral conversions that are passed to @_nonEphemeral
parameters. Currently, this defaults to a warning with a frontend flag
to upgrade to an error. Hopefully this will become an error by default
in a future language version.
2019-11-03 08:42:25 -08:00
Pavel Yaskevich
6bb659c5a3 [Diagnostics] Add a diagnostic for incorrect use of trailing closures 2019-10-31 20:58:01 -07:00
Pavel Yaskevich
d87d22d336 [ConstraintSystem] Intoduce a fix for incorrect use of trailing closures 2019-10-31 20:57:09 -07:00
Pavel Yaskevich
1315207a22 [Diagnostics] Introduce extraneous call fix
Detect and diagnose attempts to call variables and/or properties
which don't have a function type, so can't really support
invocation.
2019-10-30 16:53:42 -07:00
Pavel Yaskevich
58329e0c27 Revert "[Diagnostics][Qol] SR-11295 Emit diagnostics for same type coercion. " 2019-10-25 01:05:07 -07:00
Luciano Almeida
a92e62f51f Fixing formatting issues 2019-10-23 23:54:48 -03:00
Luciano Almeida
4385dd854f Creating UnnecessaryCoercion warning fix 2019-10-21 23:03:12 -03:00
Pavel Yaskevich
8d05192204 Merge pull request #27728 from xedin/port-extraneous-args
[Diagnostics] Diagnose extraneous argument(s) via fixes
2019-10-18 10:42:56 -07:00
Pavel Yaskevich
2a0080c6e0 [Diagnostics] Add a workaround for inability to diagnose name shadowing
Let's cover at least the most common cases - min/max. Fixing the
problem requires refactoring of `resolveDeclRefExpr`.
2019-10-16 10:19:26 -07:00
Pavel Yaskevich
04850655dc [CSFix] Make sure single parameter tuple splat is detected correctly
In situations like:

```swift
func foo<T>(x: T) {}
foo(a; 0, x: 42)
```

Let's not try to fix call to `foo` as a tuple splat because match is
in a middle of the argument list, it should be considered a regular
extraneous argument instead.
2019-10-16 10:19:26 -07:00
Pavel Yaskevich
c97603f5d4 [CSDiagnostics] Diagnose extraneous arguments 2019-10-16 10:19:25 -07:00
Pavel Yaskevich
e97164dfce [CSFix] Record all available information about extraneous arguments
Most importantly - index, label, and type, which are useful for
diagnostics.
2019-10-16 10:19:25 -07:00
Pavel Yaskevich
e33a3402cb [ConstraintSystem] Make contextual function type available for matchCallArguments
Helps diagnostics to avoid digging this type out from locator.
2019-10-16 10:19:25 -07:00
Pavel Yaskevich
f1ed46ee82 [CSFix] Add a fix to remove extraneous arguments
If there are more arguments than parameters, let's fix this by
ignoring (if possible) or removing extraneous arguments. Ignored
arguments could default to `Any` if they don't get any other
contextual type.
2019-10-16 10:19:25 -07:00
Luciano Almeida
f554dd3f51 CoerceToCheckedCast::attempt logic 2019-10-15 19:12:34 -03:00
Luciano Almeida
30ffe13cba Merge branch 'master' of https://github.com/apple/swift into force-downcast-fix-explicit-coercion 2019-10-13 11:09:37 -03:00
Luciano Almeida
171d6ec87d Adjusting tests under test/Constraints/bridging-nsnumber-and-nsvalue.swift.gyb 2019-10-13 00:42:22 -03:00
Luciano Almeida
d896968d2c clang-format 2019-10-12 22:39:12 -03:00
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
Pavel Yaskevich
7e6b4e4d57 [Diagnostics] Extend single parameter tuple splat to support generic parameters
Currently single parameter tuple splat fix/diagnostic supports only
cases where parameter is a concrete tuple type, let's enhance that to
support generic parameters as well e.g.:

```swift
func foo<T>(_: T) {}
foo(0, 1, 2) // `T` expects arguments to form a tuple e.g. `foo((0, 1, 2))`
```
2019-10-08 18:11:48 -07:00
Pavel Yaskevich
4203c2f9f3 [Diagnostics] Store synthesized arguments in missing arguments diagnostic
Since we are about to start diagnosing more than just closures,
we need information about what synthesized arguments look like.
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
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
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
3d242bd110 [ConstraintSystem] Fix a situation when argument requires raw value type of raw representable 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
34a12aa30e [Diagnostics] Add generic argument-to-parameter conversion failure
No specialized diagnostics yet, just a basic infrastructure to
produce generic a `cannot convert X to expected argument type Y`
message.
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
Suyash Srijan
bd53fe355d Revert "[CS] Don't crash when default argument is magic literal and types don't match" 2019-08-31 00:54:37 +01:00
Pavel Yaskevich
b9cf4fa6c2 [Diagnostics] Add a diagnostic for invalid conversion of inout argument/parameter
Since there is no subtyping allowed in `inout` positions, let's
produce a tailored error message and a note about that.
2019-08-28 12:19:02 -07:00
Pavel Yaskevich
844fedaaec [ConstraintSystem] Introduce a fix to allow conversion between inout types
If there is an argument-to-parameter conversion which is associated with
`inout` parameter, subtyping is now permitted, types have to be identical.

```swift
protocol P {}
struct S : P  {}

func foo(_: inout P) {}

var s = S()
foo(&s) // `s` has to be defined as `P` e.g. `var s: P = S()`
        // to be used as an argument to `inout P` parameter.
```
2019-08-28 00:56:09 -07:00
Pavel Yaskevich
7ac754acc4 [Diagnostics] Transform incorrect generic arguments into a contexual mismatch
Since this kind of failure is really a conversion failure, let's
inherit from `Contextual{Mismatch, Failure}` which also helps with
storage for from/to types and their resolution.

Also let's use original types involved in conversion to form
this fix, which helps to perserve all of the original sugar.
2019-08-19 09:56:48 -07:00
Holly Borla
cc1082146d [Diagnostics] Unify DiagnosticFailure and ConstraintFix classes for extra & failures.
Make `InvalidUseOfAddressOf` a `ContextualFailure`, make `ReturnAddressOf`
a `ContextualMismatch`, and extend this failure to cover using `&` with a
non-inout argument.
2019-08-16 17:43:59 -07:00
Holly Borla
d299925ae3 [Diagnostics] Port the "extra address of agrument" diagnostic to the new
framework.
2019-08-16 11:55:11 -07:00
Pavel Yaskevich
15ae692da0 [ConstraintSystem] Repair and diagnose failures relared to throws mismatch
If the only difference between two functions is `throws` and it
is not a subtype relationship, let's repair the problem by dropping
`throws` attribute and letting solver continue to search for
a solution, which would later be diagnosed.
2019-08-13 11:55:08 -07:00
Pavel Yaskevich
aa212d54ef [ConstraintSystem] Add a fix to ignore contextual type mismatch
Ignore contextual type mismatch to allow solver to make progress
towards solution and diagnose the problem later.
2019-08-13 11:55:08 -07:00
Pavel Yaskevich
385fb0c665 [Diagnostics] Make force downcast fix contextual and move it to repairFailures
This way it covers a lot more ground and doesn't conflict with
other fixes.

Another notable change is related to check for IUO associated
with source type, that covers cases like:

```swift
func foo(_ v: NSString!) -> String {
  return v
}
```

Instead of general conversion failure check for IUO enables solver
to introduce force downcast fix.
2019-08-09 01:09:52 -07:00
Pavel Yaskevich
a34fe9ae55 [Diagnostics] Extend missing & diagnostic to cover pointer conversions
Example:

```swift
func foo(_: UnsafePointer<Int>) {}

var x: Int = 0
foo(x) <- should suggest adding `&`
```
2019-08-06 17:52:24 -07:00
Holly Borla
edcf4055d2 [Diagnostics] Use ContextualFailure and ContextualMistatch as base classes
for `AutoClosurePointerConversionFailure` and `AllowAutoClosurePointerConversion`
respectively.
2019-08-02 15:23:25 -07:00
Holly Borla
e76f5f1d0b [Diagnostics] Improve the diagnostic for invalid pointer conversion for an autoclosure result type.
Add constraint fix `AllowAutoClosurePointerConversion` and corresponding diagnostic
`AutoClosurePointerConversionFailure`. When we discover that we're trying to do an
inout-to-pointer conversion in `matchTypes`, add the constraint fix, which tries to do the
conversion as if the pointer type is a regular function argument.
2019-08-02 14:16:06 -07:00
Pavel Yaskevich
2cfcdf49dc Merge pull request #26391 from sl/port-tuple-assignment-diagnostic
[Diagnostics] Ported tuple mismatch diagnostic to new diagnostic framework
2019-08-02 13:22:52 -07:00