Commit Graph

462 Commits

Author SHA1 Message Date
Luciano Almeida
49e8eee3e5 [CSDiagnostics] Handle CoercionExpr empty path in ContextualMismatch 2020-01-04 15:59:13 -03:00
Pavel Yaskevich
8bcc192591 [Diagnostics] Diagnose inability to infer (complex) closure return type 2019-12-19 12:16:30 -08:00
Pavel Yaskevich
d77e34925f [ConstraintSystem] Lift a restriction on fixing of non-function calls on Any/AnyObject
Detect and diagnose situations where call is attempted directly on
`Any` or `AnyObject` or member calls with `AnyObject` base which
didn't match.
2019-12-13 22:50:04 -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
382013f788 [Diagnostics] Convert missing @escaping diagnostic to contextual failure
This gives diagnostic access to both sides of a conversion/binding
which makes it easier to diagnose errors associated with generic parameters.
2019-12-12 12:42:25 -08:00
Pavel Yaskevich
cc50b46345 [Diagnostics] Preserve raw from/to types in contextual mismatch diagnostic
This is useful in some situations where access to type variable(s)
helps to diagnose the problem properly e.g. if it's a conversion
to generic parameter.
2019-12-12 12:42:19 -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
Brent Royal-Gordon
da88512eda [NFC] Take DeclNameRef in UnqualifiedLookup and lookupQualified() 2019-12-11 00:55:17 -08:00
Holly Borla
edb4e70d66 Merge pull request #28600 from hborla/tuple-mismatch-diagnostics
[ConstraintSystem] Port tuple type mismatch diagnostics
2019-12-09 13:26:34 -08:00
Holly Borla
94e9fd1d67 [Diagnostics] Use a generic "tuple type not convertible" error message
when there is no contextual type.
2019-12-09 11:25:32 -08:00
Pavel Yaskevich
21a8b3c57d [Diagnostics] Port tailored diagnostics for missing dynamicallyCall methods 2019-12-06 16:43:18 -08:00
Pavel Yaskevich
184e238707 [Diagnostics] Improve diagnostics for mutating callAsFunction used on r-value 2019-12-06 16:43:18 -08:00
Holly Borla
1e013a02cf [ConstraintSystem] Move FailureDiagnostic::getFunctionArgApplyInfo
into `ConstraintSystem`.
2019-12-06 15:43:39 -08:00
Holly Borla
f9a1ab28f4 [ConstraintSystem] Port tuple type mismatches to the new framework 2019-12-06 13:12:57 -08:00
Hamish Knight
a97328dcbf [CS] Use a MapVector to cache resolved overloads
Rather than maintaining a linked list of overload
choices, which must be linearly searched each time
we need to lookup an overload at a given callee
locator, use a MapVector which can be rolled back
at the end of a scope.

Remove ResolvedOverloadSetListItem in favor of
using SelectedOverload, which avoids the need to
convert between them when moving from
ConstraintSystem to Solution.
2019-12-05 14:47:52 -08:00
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