Pavel Yaskevich
2875aa8e2b
[Diagnostics] Diagnose an attempt to init/use dictionary with array literal in CSGen
...
It's much easier to detect that contextual type is a dictionary
but expression is an array literal while generating constraints.
2020-02-06 09:32:07 -08:00
Pavel Yaskevich
c5ae6c96a9
[ConstraintSystem] Detect missing/extraneous arguments even if there is optional injection required
...
If parameter type is optional let's ignore that since argument could
be either optional itself or be injected into optional implicitly.
```swift
func foo(_: ((Int, Int) -> Void)!) {}
foo { _ in } // Missing second closure parameter
```
2020-02-05 12:11:01 -08:00
Pavel Yaskevich
506cd7d858
[ConstraintSystem] Let optional chaining infer a type from sub-expression even with contextual mismatch
...
Just like in case of `try?` it makes it easier to distinguish between
missing optional unwrap and contextual type mismatch.
2020-02-05 12:11:01 -08:00
Pavel Yaskevich
fb0a484a08
[ConstraintSystem] Let try? infer type from sub-expression even with contextual mismatch
...
This helps to diagnose contextual mismatches like `Int? vs. Bool`
instead of suggesting to unwrap the optional which would still
produce an incorrect type.
2020-02-05 12:11:01 -08:00
Pavel Yaskevich
956b9f27b4
Merge pull request #29628 from owenv/condition_diags
...
[Diagnostics] Improve diagnostics for optional/integer as boolean condition
2020-02-04 08:49:36 -08:00
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
swift-ci
b6d9dcca46
Merge pull request #29589 from DougGregor/expr-type-check-flag-cleanups
2020-01-31 23:51:20 -08:00
Doug Gregor
c5ed8d67a9
[Constraint solver] Fix tautological assert.
2020-01-31 21:40:39 -08:00
swift-ci
8c8f5b1eb1
Merge pull request #29588 from DougGregor/silence-the-listeners
2020-01-31 20:02:13 -08:00
Doug Gregor
4b0e7b2780
[Type checker] Sink logic for @autoclosure default parameters into the solver
...
Rather than use an ExprTypeCheckListener subclass to introduce the
autoclosure expression, do it at the end of solving.
2020-01-31 18:20:46 -08:00
Pavel Yaskevich
c9c20afe27
[Diagnostics] Port name shadowing diagnostics
...
Diagnose an attempt to reference a top-level name shadowed by
a local member e.g.
```swift
extension Sequence {
func test() -> Int {
return max(1, 2)
}
}
```
Here `min` refers to a global function `min<T>(_: T, _: T)` in `Swift`
module and can only be accessed by adding `Swift.` to it, because `Sequence`
has a member named `min` which accepts a single argument.
2020-01-29 09:14:24 -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