Commit Graph

195 Commits

Author SHA1 Message Date
Luciano Almeida
02c454c976 [Diagnostics] Diagnose that we cannot infer the key path type when binding to a hole 2020-05-11 18:08:40 -03:00
Artem Chikin
7aed042817 Add fix on Keypath -> Function with multiple arguments type mismatch.
When simplifying a keypath constraint with a function type binding, single-parameter functions have the parameter type and the return type matched against the keypath root and value; whereas multiple-parameter functions cause an ambiguous failure (in `simplifyKeyPathConstraint`).

Resolves rdar://problem/57930643
2020-05-06 19:15:08 -07:00
Pavel Yaskevich
bd09d0c776 [ConstraintSystem] Switch ConstraintFix to use ASTNode instead of TypedNode 2020-04-29 17:03:45 -07:00
Joe Groff
b4c7a7e85d Merge pull request #31224 from AnthonyLatsis/rename-getfullname-2
AST: Rename getFullName -> getName on ValueDecl & MissingMemberDecl
2020-04-24 12:51:28 -07:00
Pavel Yaskevich
12a63ce907 [ConstraintSystem] Switch getContextualType and its variants to use TypedNode 2020-04-23 01:13:13 -07:00
Pavel Yaskevich
7669e0d059 [CSFix] Switch ConstraintFix::getAnchor to return TypedNode 2020-04-23 01:13:13 -07:00
Anthony Latsis
74252028ca AST: Rename getFullName -> getName on ValueDecl & MissingMemberDecl 2020-04-23 05:16:55 +03:00
Luciano Almeida
f18fe0960f [CSFix] Create AllowKeyPathRootTypeMismatch to diagnose key path root fail on key path application 2020-04-21 17:41:50 -03:00
Hamish Knight
d69a42d656 [CS] Preserve compatibility for collection coercions
Previously we could allow some invalid coercions to
sneak past Sema. In most cases these would either
cause crashes later down the pipeline or
miscompiles. However, for coercions between
collections, we emitted somewhat reasonable code
that performed a force cast.

This commit aims to preserve compatibility with
those collection coercions that previously
compiled, and emits a warning telling the user to
use either 'as?' or 'as!' instead.
2020-04-10 10:16:07 -07:00
Holly Borla
ece84b176c [Diagnostics] Adjust ConstraintFix::diagnoseForAmbiguity to take an array
ref of pairs rather than two parallel arrays.
2020-04-07 13:38:26 -07:00
Holly Borla
6375481ea4 [Diagnostics] In DefineMemberBasedOnUse::diagnoseForAmbiguity, use
the base type from each solution instead of only the base type from
the first solution.
2020-04-06 17:35:31 -07:00
Luciano Almeida
faba29a55f [Diagnostics] Diagnose key path reference to initializer methods. 2020-03-28 16:32:08 -03:00
Pavel Yaskevich
7800a04de3 [Diagnostics] Adjust "missing arguments" diagnostic to store parameter indices directly
This helps to avoid allocating new type variables (which shouldn't be done regardless)
to store parameter indices when `missing arguments` diagnostic is used by other diagnostics.
2020-03-13 16:55:37 -07:00
Pavel Yaskevich
3ab8710329 [Diagnostics] Cleanup use of constraint system by ConstraintFix/FailureDiagnostic 2020-03-13 15:02:10 -07:00
Pavel Yaskevich
0fc9d1b84a [Diagnostics] Move getFunctionArgApplyInfo to Solution
Instead of relying on constraint system having solution applied
let's pass a solution directly to `getFunctionArgApplyInfo`.
2020-03-13 12:46:25 -07:00
Pavel Yaskevich
1fc0ea6b0e [CSFix] Allow diagnose to accept a solution to diagnose
Instead of always applying solution back to constraint system
before diagnostics, let's pass solution directly to `ConstaintFix::diagnose`
method to be used by `FailureDiagnostic` which paves a way for
stateless diagnostics.
2020-03-12 11:41:36 -07:00
Pavel Yaskevich
bb656e120d [CSFix] Teach getStructuralTypeContext about tuple initialization calls 2020-02-17 16:09:11 -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
Holly Borla
651c27b50b [Diagnostics] Add CSFix::diagnoseForAmbiguity for diagnosing common
fixes that appear in all solutions.
2020-02-11 14:53:27 -08:00
Pavel Yaskevich
96441c1129 [CSFix] Account for nested structural errors related to function argument mismatches
When it comes to contextual mismatches `ContextualType` is not guaranteed
to be the last element in the patch since contextual type could be a function
too which could would have `contextual type -> function argument` path.
2020-02-06 09:30:19 -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
7351bfc86f [CSFix] Add a fix to add a missing qualifier to shadowed top-level name references 2020-01-29 09:14:24 -08:00
Pavel Yaskevich
b2083db45d [ConstraintSystem] Add a fix to allow conversion between non-class type and AnyObject 2020-01-29 00:06:57 -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
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
Holly Borla
94bbb8f76e [ConstraintSystem] Finish porting unresolved member reference failures.
This covers member failures where the error is at the declaration, so
the result of member lookup is "already diagnosed".
2020-01-05 11:33:02 -08:00
Pavel Yaskevich
8bcc192591 [Diagnostics] Diagnose inability to infer (complex) closure return type 2019-12-19 12:16:30 -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
f259286bd7 [CSFix] Convert missing explicit @escaping fix to be a contextual mismatch
Sometimes diagnostic needs both sides of the conversion e.g.
when there is an attempt to bind generic argument to non-escaping type.
2019-12-12 12:42:08 -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
Holly Borla
50abedd45c [Diagnostics] Keep track of the indices of the tuple elements whose
types do not match in AllowTupleTypeMismatch/TupleContextualFailure.
2019-12-09 11:04:34 -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
Pavel Yaskevich
3c5290c78c [Diagnostics] Diagnose inability to infer contextual base type for member ref 2019-12-03 12:07:16 -08:00
Pavel Yaskevich
ac1ab1dfb0 [CSFix] Fix inability to infer contextual base type for member ref 2019-12-03 12:07:16 -08:00
Pavel Yaskevich
15c58d19d5 [ConstraintSystem] Detect passing array to variadic argument in function conversions
Initially this problem was only detected and diagnosed for calls.
So let's extend it to function conversions as well e.g.:

```swift
func foo<T>(_: [T]) {}
func bar<T>(_ f: (T...) -> ()) {}

bar { foo($0) }
```
2019-12-03 12:07:15 -08:00
Pavel Yaskevich
bdeaced0f2 [CSFix] Convert force optional unwrap fix into a contextual one 2019-11-19 15:15:29 -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
Holly Borla
ea1a46c84d [ConstraintFix] Rather than creating a coalesced fix right before
diagnosing failures in applySolutionFixes, coalesce fixes and
diagnose failures in one method on ConstraintFix.

This eliminates the need for the `DefaultGenericArgument` fix (which
was renamed from `ExplicitlySpecifyGenericArguments`) to have an
array of missing parameters, which was only used when the fixes were
coalesced. Instead, the coalesced arguments are used to create the
`MissingGenericArgumentsFailure` diagnostic directly.
2019-11-13 14:15:40 -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
Robert Widmann
7b9d28d7ba Make diagnoseSelfAssignment a utility 2019-11-06 15:08:59 -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
Holly Borla
e840d52258 [Diagnostics] Allow fixes with the same locator to be coalesced before
application rather than throwing away subsequent fixes.

The "primary fix" decides whether or not to coalesce fixes that have
the same locator.
2019-11-05 09:15:13 -08:00
Hamish Knight
65dda6d945 Address other review feedback 2019-11-03 08:42:26 -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