Commit Graph

485 Commits

Author SHA1 Message Date
Owen Voorhees
166555c34f [Diagnostics] Better diagnostic for integer used as a boolean condition 2020-02-03 21:20:41 -08:00
Owen Voorhees
4aca39e18e [Diagnostics] Provide a better fix-it when trying to boolean-negate an optional 2020-02-03 17:40:03 -08:00
Pavel Yaskevich
ec3b783380 [Diagnostics] Improve diagnostic for invalid conversion to AnyObject 2020-01-29 00:37:39 -08:00
Pavel Yaskevich
38aded73b1 [Diagnostics] Add a special case diagnostic for call to init on Void with arguments
Expressions like `Void(...)` have a special locator which ends at
`FunctionArgument` instead of `ApplyArgument` which makes it possible
to type-check `Void()` call successfully. "extraneous arguments" diagnostic
needs to handle such situations specifically e.g. `Void(0)`.
2020-01-28 00:35:51 -08:00
Pavel Yaskevich
0dcb78fe69 Merge pull request #29389 from xedin/rdar-50666427
[Diagnostics] Unsatisfied requirement `in reference` diagnostics expe…
2020-01-24 09:30:12 -08:00
Doug Gregor
1e3484c1bf [Constraint solver] Dig out the root expression as the "contextual node". 2020-01-23 13:20:31 -08:00
Doug Gregor
133439dcbb [Constraint solver] Request contextual type information per expression.
When requesting information about the contextual type of a constraint
system, do so using a given expression rather than treating it like
the global state that it is.
2020-01-23 11:46:17 -08:00
Pavel Yaskevich
d412ea4d16 [Diagnostics] Unsatisfied requirement in reference diagnostics expect type context
Resolves: rdar://problem/50666427
2020-01-23 10:14:37 -08: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
Luciano Almeida
fb12c09188 [NFC] Fixing minor comments that should be docs and minor call 2020-01-20 21:35:22 -03:00
Doug Gregor
bfa6d7316d [Function builders] Fake Expr-based locators for now.
The right solution is to extend the notion of the "anchor" of a locator
to also cover statements (and TypeReprs, and Patterns, and more), so
this is a stop-gap.
2020-01-16 13:19:21 -08:00
Pavel Yaskevich
36216d5871 [Diagnostics] Pinpoint contextual error location if it's related to a call to closure
For example `let _: B = { A() }()` should point to a closure result
instead of a call.
2020-01-14 00:09:32 -08:00
Pavel Yaskevich
83744d9d39 [Diagnostics] Use ´isa instead of dyn_cast` because array/dictionary expr in unused 2020-01-13 12:53:30 -08:00
Pavel Yaskevich
2164476bf5 [Diagnostics] Port diagnostics related to dictionary literal use 2020-01-13 12:41:07 -08:00
Pavel Yaskevich
f2942ebb56 [Diagnostics] Port diagnostics related to array literal use 2020-01-13 11:54:59 -08:00
Holly Borla
9ddb5eddc5 Merge pull request #29065 from hborla/subscript-error-diag
[Diagnostics] Finish porting subscript errors
2020-01-08 16:05:04 -08:00
Luciano Almeida
4443966f3d [CSDiagnostics] Removing duplicated diagnose for InstanceType 2020-01-08 07:11:17 -03:00
Luciano Almeida
06201a64be [Sema] Diagnose wrong type coercion involving metatypes 2020-01-08 07:07:49 -03:00
Holly Borla
834eee6f4e [Diagnostics] Implement MissingArgumentsFailure::diagnoseAsNote in order
to diagnose ambiguities due to missing arguments.
2020-01-07 17:37:38 -08:00
Pavel Yaskevich
be3f949a43 [Diagnostics] Add support for new "ternary branch" element to contextual mismatch 2020-01-07 12:07:02 -08:00
Luciano Almeida
64f8a6bd42 [CSDiagnostics] Renaming ContextualFailure CoerceExpr method naming 2020-01-06 14:37:27 -03:00
Luciano Almeida
a1bf54af51 [CSDiagnostics] Extract diagnostic for CoerceExpr to function 2020-01-04 23:41:14 -03:00
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