Commit Graph

148 Commits

Author SHA1 Message Date
Luciano Almeida
e598f6118e [ConstraintSystem] Improve check for record SpecifyObjectLiteralTypeImport and fix string description 2020-01-21 20:55:08 -03:00
Luciano Almeida
716e11f575 [Constraint System] Recording SpecifyObjectLiteralTypeImport fix when attempting literal result type variable binding and handle object literal in MissingArgumentsFailure 2020-01-21 20:39:44 -03:00
Luciano Almeida
68e09d64fd [CSFix] Creating object literal module import fix 2020-01-21 11:54:26 -03:00
Holly Borla
94bbb8f76e [ConstraintSystem] Finish porting unresolved member reference failures.
This covers member failures where the error is at the declaration, so
the result of member lookup is "already diagnosed".
2020-01-05 11:33:02 -08:00
Pavel Yaskevich
8bcc192591 [Diagnostics] Diagnose inability to infer (complex) closure return type 2019-12-19 12:16:30 -08:00
Pavel Yaskevich
5ba2e59c63 Merge pull request #28752 from xedin/simplify-potential-binding
[ConstraintSystem] Record originator constraint for each type variable binding
2019-12-13 11:50:02 -08:00
Pavel Yaskevich
f259286bd7 [CSFix] Convert missing explicit @escaping fix to be a contextual mismatch
Sometimes diagnostic needs both sides of the conversion e.g.
when there is an attempt to bind generic argument to non-escaping type.
2019-12-12 12:42:08 -08:00
Holly Borla
3d1ab4da67 Merge pull request #28712 from hborla/function-parameter-mismatch-diagnostics
[ConstraintSystem] Port function parameter type mismatch diagnostics.
2019-12-11 14:33:07 -08:00
Holly Borla
51c7c8c8f1 [ConstraintSystem] Port function parameter type mismatch diagnostics. 2019-12-11 10:45:52 -08:00
Brent Royal-Gordon
addbe3e5ed [NFC] Thread DeclNameRef through most of the compiler
This huge commit contains as many of the mechanical changes as possible.
2019-12-11 00:55:18 -08:00
Holly Borla
50abedd45c [Diagnostics] Keep track of the indices of the tuple elements whose
types do not match in AllowTupleTypeMismatch/TupleContextualFailure.
2019-12-09 11:04:34 -08:00
Holly Borla
f9a1ab28f4 [ConstraintSystem] Port tuple type mismatches to the new framework 2019-12-06 13:12:57 -08:00
Pavel Yaskevich
ac1ab1dfb0 [CSFix] Fix inability to infer contextual base type for member ref 2019-12-03 12:07:16 -08:00
Pavel Yaskevich
bdeaced0f2 [CSFix] Convert force optional unwrap fix into a contextual one 2019-11-19 15:15:29 -08:00
Holly Borla
ea1a46c84d [ConstraintFix] Rather than creating a coalesced fix right before
diagnosing failures in applySolutionFixes, coalesce fixes and
diagnose failures in one method on ConstraintFix.

This eliminates the need for the `DefaultGenericArgument` fix (which
was renamed from `ExplicitlySpecifyGenericArguments`) to have an
array of missing parameters, which was only used when the fixes were
coalesced. Instead, the coalesced arguments are used to create the
`MissingGenericArgumentsFailure` diagnostic directly.
2019-11-13 14:15:40 -08:00
Holly Borla
7f2d4c0a99 [CSApply] When applying constraint fixes for a solution, only coalesce
fixes of the same kind.
2019-11-11 10:08:25 -08:00
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
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
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
2dddfcb190 Merge pull request #28013 from xedin/trailing-closures-not-so-trailing
[Diagnostics] Port invalid trailing closure use diagnostics
2019-11-01 15:38:20 -07:00
Pavel Yaskevich
d87d22d336 [ConstraintSystem] Intoduce a fix for incorrect use of trailing closures 2019-10-31 20:57:09 -07:00
Brent Royal-Gordon
17169fc1fe Merge pull request #27950 from brentdax/dumpster-fire
[NFC] Standardize dump() methods in frontend
2019-10-31 20:36:26 -07:00
Brent Royal-Gordon
99faa033fc [NFC] Standardize dump() methods in frontend
By convention, most structs and classes in the Swift compiler include a `dump()` method which prints debugging information. This method is meant to be called only from the debugger, but this means they’re often unused and may be eliminated from optimized binaries. On the other hand, some parts of the compiler call `dump()` methods directly despite them being intended as a pure debugging aid. clang supports attributes which can be used to avoid these problems, but they’re used very inconsistently across the compiler.

This commit adds `SWIFT_DEBUG_DUMP` and `SWIFT_DEBUG_DUMPER(<name>(<params>))` macros to declare `dump()` methods with the appropriate set of attributes and adopts this macro throughout the frontend. It does not pervasively adopt this macro in SILGen, SILOptimizer, or IRGen; these components use `dump()` methods in a different way where they’re frequently called from debugging code. Nor does it adopt it in runtime components like swiftRuntime and swiftReflection, because I’m a bit worried about size.

Despite the large number of files and lines affected, this change is NFC.
2019-10-31 18:37:42 -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
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
73dcc4b5e8 Merge branch 'master' of https://github.com/apple/swift into force-downcast-fix-explicit-coercion 2019-10-15 19:18:46 -03:00
Hamish Knight
f1c2df1878 Allow arg mismatch subclasses to be warnings 2019-10-15 10:12:49 -07:00
Luciano Almeida
d896968d2c clang-format 2019-10-12 22:39:12 -03:00
Luciano Almeida
f39ff88113 Initial implementation of moving the checks 2019-10-12 15:22:16 -03: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
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
0f24f7e05a [CSFix] Introduce a fix for argument-to-parameter conversion mismatch 2019-09-13 22:35:50 -07:00
Holly Borla
7277f4f4ed [Diagnostics] Extend the AllowInOutConversion fix to cover inout attribute
mismatches in function types.

This improves the diagnostic in cases where we have argument-to-parameter
conversion failures or contextual type mismatches due to inout attribute
mismatches.
2019-09-05 14:16:24 -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
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
Holly Borla
0cdfda0eb9 Merge pull request #26541 from hborla/autoclosure-optional-ptr-conversion-diag
[Diagnostics] Improve the diagnostic for invalid optional pointer conversions for an autoclosure result type.
2019-08-20 10:58:33 -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