Commit Graph

503 Commits

Author SHA1 Message Date
Pavel Yaskevich
2dccdbfabf [ConstraintSystem] NFC: Remove workarounds related to (now deprecated) CSDiag 2020-02-18 10:13:09 -08:00
Pavel Yaskevich
ca91a1bee0 [ConstraintSystem] Detect and diagnose OoO arguments in call to binary functions/operators
Identify problems like:

```swift
func foo(_ x: Int, _ y: String) {}

func bar(a: Int, b: String) {
  foo(b, a) // Instead of `foo(a, b)`
}
```

Where arguments are out-of-order and repair it by using OoO fix on the
parent locator.
2020-02-17 16:09:11 -08:00
Pavel Yaskevich
df21cbf85c [ConstraintSystem] Ignore attempt to bind type var to dependent member with incorrect base
Just like in cases where both sides are dependent member types
with resolved base that can't be simplified to a concrete type
let's ignore this mismatch and mark affected type variable as a hole
because something else has to be fixed already for this to happen.
2020-02-17 16:09:11 -08:00
Pavel Yaskevich
355148dbe8 Merge pull request #29746 from hborla/ambiguity-with-fixes
[Diagnostics] Refactor diagnoseAmbiguityWithFixes.
2020-02-13 02:42:43 -08:00
Pavel Yaskevich
5437622d2d [Diagnostics] Diagnose ambiguity with conflicting arguments to generic parameters
It's done by first retrieving all generic parameters from each solution,
filtering boundings into distrinct set and diagnosing any differences.

For example:

```swift
func foo<T>(_: T, _: T) {}
func bar(x: Int, y: Float) {
  foo(x, y)
}
```
2020-02-12 17:53:31 -08:00
Robert Widmann
054d7b9913 Merge pull request #29713 from CodaFi/unused-unwanted-unloved
[Gardening] Silence Some Warning Spew
2020-02-11 15:46:16 -08:00
Suyash Srijan
211394099f [CSDiagnostics] Offer a fix-it to insert a return type placeholder when returning from a void function (#29747)
* [CSDiagnostics] Offer a fix-it to insert a return type when returning from a void function

* [CSDiagnostics] Make sure the function name is not empty

The function name will be empty in some cases, for example for property setters. In cases where the function name is empty, skip the note and fix-it.

* [Test] Update existing diagnostics
2020-02-11 10:25:16 +00:00
Robert Widmann
d2360d2e8c [Gardening] dyn_cast -> isa 2020-02-07 16:09:31 -08:00
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