Commit Graph

1245 Commits

Author SHA1 Message Date
Pavel Yaskevich
805a5e9a1e [Diagnostics] Extend missing argument(s) diagnostic to support closure returns
If return type is a function, it's possible to return a closure
which can have some of its arguments unused in the body e.g.

`let _: () -> ((Int) -> Void) = { return { } }`

In this case resulting closure has to use its only parameter or
explictly ignore it by declaring `_ in`.
2019-12-04 14:22:46 -08:00
Pavel Yaskevich
3c5290c78c [Diagnostics] Diagnose inability to infer contextual base type for member ref 2019-12-03 12:07:16 -08:00
Pavel Yaskevich
34f5b52db1 [Diagnostics] Diagnose ambiguities related to contextual type mismatch
If none of the candidates produce expected contextual type, record
all of the posibilities to produce a note per and diagnose this as
contextual type mismatch instead of a reference ambiguity.
2019-12-03 12:07:15 -08:00
Pavel Yaskevich
a9f11445c0 [Diagnostics] Diagnose an attempt to assign a value to an overloaded name
Example:

```swift
struct X {
}

func X(_: Int) -> Int {
  return 42
}

X = 42
```
2019-12-03 12:07:15 -08:00
Hamish Knight
88b84c25b2 NFC: Remove an unnecessary use of NL_RemoveNonVisible
NL_QualifiedDefault already implies it.
2019-11-21 16:21:57 -08:00
Pavel Yaskevich
38a6cfaad1 [CSDiagnostic] Convert force optional unwrap diagnostic into a contextual one
Record both sides of conversion where a form of force unwrap is
necessary to be able to produce tailored diagnostics such as for
an attempt to use optional type as a boolean.
2019-11-19 15:15:29 -08:00
Holly Borla
eef34add12 Merge pull request #28343 from hborla/restrain-param-tuple-splat-fix
[Diagnostics] Don't apply the single parameter tuple splat fix if the parameter type is a generic parameter.
2019-11-18 18:03:51 -08:00
Holly Borla
a9a0bba31b [Diagnostics] Don't apply the single parameter tuple splat fix if the
parameter type is a generic parameter.
2019-11-18 16:19:33 -08:00
Hamish Knight
6d6feb60de [CSDiagnostics] Support static "Type." fix-it
Check whether we found a static property, and if
so, suggest inserting "Type." instead of "self.".

Resolves SR-11788.
2019-11-15 11:12:12 -08:00
Hamish Knight
37e15dbf44 [CSDiagnostics] Use expr's start loc for 'self.' fix-it
Resolves SR-11787.
2019-11-15 11:12:12 -08:00
Hamish Knight
8d208be40a [CSDiagnostics] Use qualified lookup for 'self.' fix-it
We only want to look for properties on the type
which the method is a member of.

Resolves SR-11786.
2019-11-15 11:12:11 -08:00
Hamish Knight
5eb1df532b [CSDiagnostics] NFC: Use std::tie to call resolveImmutableBase 2019-11-15 11:12:11 -08:00
Holly Borla
5bb50068ac Merge pull request #28243 from hborla/missing-generic-args-refactoring
[ConstraintSystem] Missing generic args/hole refactoring
2019-11-14 13:48:40 -08:00
swift-ci
0103fe1eac Merge pull request #28265 from DougGregor/diagnose-ambiguity-with-fixes-without-expr 2019-11-14 12:57:32 -08:00
Doug Gregor
4c2a7bf1ac Revert "[Constraint solver] Be more careful about NULL parent expression."
This reverts commit 0e269a5127.
2019-11-13 17:23:27 -08:00
Holly Borla
c0312b9c0e [ConstraintSystem] Record holes in the constraint system using a new flag in
`TypeVariableOptions` rather than using a separate data structure in the
constraint system.
2019-11-13 15:46:36 -08:00
Pavel Yaskevich
431ca98246 [Diagnostics] Port explicit closure result contextual mismatch
Detect and diagnose a problem when explicitly specified closure
result type doesn't match what is expected by the context:

Example:

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

foo { () -> String in "" } // `Int` vs. `String`
```
2019-11-13 14:05:59 -08:00
Pavel Yaskevich
a7bc52fd9a Merge pull request #28197 from xedin/handle-single-pd-arg-mismatch
[Diagnostics] Produce a tailored diagnostic for property wrapper argu…
2019-11-11 15:13:56 -08:00
Pavel Yaskevich
08f8f4191d [Diagnostics] Produce a tailored diagnostic for property wrapper argument mismatch
Diagnose an attempt to initialize a property, which has a property
wrapper, with a value of an incorrect type.
2019-11-11 12:59:28 -08:00
Robert Widmann
1b75dbd43c Remove TypeChecker::Diags 2019-11-10 15:36:57 -08:00
Robert Widmann
1000c9d19e Remove some ancillary TypeCheckers 2019-11-10 14:29:05 -08:00
Robert Widmann
1123b1f897 Move constraint satisfiability utilities 2019-11-10 13:12:50 -08:00
Robert Widmann
63896c1fc5 Make more high-level type checking endpoints utility 2019-11-10 13:03:46 -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
Doug Gregor
3fbdac5190 [Failure diagnostic] Use the constraint system's parent map. 2019-11-08 21:39:27 -08:00
Doug Gregor
a7d6deb09a [Constraint system] Use parent of anchor for trailing closure ambiguity. 2019-11-08 21:35:03 -08:00
Doug Gregor
c744066c52 [Constraint solver] Stop using the "root expression" in failure diagnostics.
We're still using the root expression to find the parent map, but we're not
falling back to it indiscriminately. Use the parent of the anchor (or
appropriate substitute) instead so we have a better handle on which
expression we're diagnosing for.
2019-11-08 21:26:04 -08:00
Doug Gregor
0e269a5127 [Constraint solver] Be more careful about NULL parent expression. 2019-11-08 21:26:04 -08:00
Robert Widmann
41ab235797 [CS] Remove some TypeChecker uses 2019-11-07 12:41:37 -08:00
Hamish Knight
b57c86dc1c fixItEncloseTrailingClosure doesn't need a TypeChecker 2019-11-07 12:41:36 -08:00
Robert Widmann
fb8b0600ad Remove some remaining TypeCheckers 2019-11-06 15:08:59 -08:00
Robert Widmann
7b9d28d7ba Make diagnoseSelfAssignment a utility 2019-11-06 15:08:59 -08:00
Pavel Yaskevich
6d02fb7815 Merge pull request #28057 from xedin/assign-diags
[Diagnostics] Port the rest of assignment diagnostics to the new framework
2019-11-06 00:11:08 -08:00
Robert Widmann
53f2974e27 [NFC] Remove unnecessary TypeCheckers from sequence folding 2019-11-05 20:30:40 -08:00
Robert Widmann
e907d3bc52 [NFC] Remove the TypeChecker from Typo Correction 2019-11-05 20:29:36 -08:00
Hamish Knight
96e5f2a145 Allow non-ephemeral diag to refer to argument labels
Use getArgDescription to improve the diagnostic
for invalid temporary pointer conversions.
2019-11-05 13:51:53 -08:00
Hamish Knight
912a7acc1e Add FunctionArgApplyInfo::getArgDescription
This commit adds a member which produces a string
describing the argument being applied. This will
either be its argument label or position in the
argument list.
2019-11-05 13:51:53 -08:00
Pavel Yaskevich
c800bde8e1 [Diagnostics] Try to find overlap between src/dst protocols in assignment mismatch 2019-11-05 12:43:32 -08:00
Pavel Yaskevich
11644b3f31 [Diagnostics] Diagnose assignment type mismatches related to unresolved members 2019-11-05 12:43:32 -08:00
Pavel Yaskevich
3586af6e8a [Diagnostics] Properly diagnose assignment type mismatches when either side is optional 2019-11-05 12:38:13 -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
Pavel Yaskevich
cb3a0fbcc8 [ConstraintSystem] Extend use of the treat r-value as l-value fix to more cases
Cover not only immutability but also type mismatch cases and clarify
behavior when one of the sides of the type conversion is optional.
2019-11-05 12:38:13 -08:00
Hamish Knight
d0dbbf9f89 [CSDiagnostics] Add ephemeralness ambiguity notes 2019-11-03 08:42:25 -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
6bb659c5a3 [Diagnostics] Add a diagnostic for incorrect use of trailing closures 2019-10-31 20:58:01 -07:00
Robert Widmann
8a69f886ad Merge pull request #27955 from AnthonyLatsis/bracestmt_cleanup
NFC: Solidify and tidy up the BraceStmt interface
2019-10-31 13:48:40 -07:00
Pavel Yaskevich
82c2456295 Merge pull request #27976 from xedin/extraneous-call
[Diagnostics] Introduce extraneous call fix
2019-10-31 11:57:03 -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