Commit Graph

1026 Commits

Author SHA1 Message Date
Pavel Yaskevich
6cdd981ee1 Merge pull request #25080 from owenv/improve_subscript_assignment_diag
[Diagnostics] Clarify diagnostic for failed type conversion in subscript assignment
2019-06-04 19:33:23 -07:00
Pavel Yaskevich
2f3809c5b3 Merge pull request #25149 from xedin/diag-missing-generic-args
[ConstraintSystem] Detect and diagnose missing generic arguments
2019-05-31 13:04:00 -07:00
Sam Lazarus
dc886ebe47 Sema: Move call to getRValueType inside of getBaseType 2019-05-30 19:07:25 -04:00
Sam Lazarus
147280ac3b Sema: Renamed invalid member ref on existential fix, and refactored inheritance 2019-05-30 18:48:58 -04:00
Sam Lazarus
0714dfe607 Sema: Convert to rvalue type before diagnosing protocol type member failure 2019-05-30 18:35:20 -04:00
Pavel Yaskevich
da799ebe51 [Diagnostics] Add a note if missing parameter is associated with generic subscript 2019-05-30 14:43:37 -07:00
Pavel Yaskevich
5e35c3e445 [Diagnostics] Replace CSDiag logic for diagnosing missing generic arguments with new diagnostic 2019-05-30 12:38:17 -07:00
Pavel Yaskevich
d0a956098b [Diagnostics] Move findArgumentLocations logic from fix to diagnostic 2019-05-30 11:27:20 -07:00
Sam Lazarus
6af91cc08d Sema: Removed unnecessary ValueDecl from AllowProtocolTypeMember
Additionally removed the same unnecessary ValueDecl from
AllowProtocolTypeMemberFailure allowing it to extend MissingMemberFailure.
2019-05-30 01:03:46 -04:00
Sam Lazarus
049ec0f851 Sema: Port member access on existentials diagnostic to new diagnostic framework 2019-05-30 00:32:01 -04:00
Pavel Yaskevich
44536fe2e0 [Diagnostics] Improve missing generic argument diagnostic notes
Emit separate notes for generic parameters found in operator, initializer
and function declarations. As well as clarify types of `declared in type`
note.
2019-05-29 10:26:05 -07:00
Pavel Yaskevich
e97955e7c7 [Diagnostics] Add a new diagnostic for missing generic arguments 2019-05-29 10:26:04 -07:00
Owen Voorhees
8e1c00cb46 [Diagnostics] Clarify diagnostic for failed type conversion in subscript assignment
Addresses SR-6340
2019-05-28 18:58:41 -07:00
Pavel Yaskevich
866e8f51fa [Diagnostics] Let invalid member ref carry member declaration instead of looking it up
All places where `invalid member ref` fix/diagnostic is used already
have a reference to the potential member choice declaration, which
diagnostic could take advantage of.
2019-05-21 11:49:03 -07:00
Pavel Yaskevich
48688241c3 [Diagnostics] Add known member declaration to invalid member ref diagnostic
This is useful for `CSDiag` when it detects that all
overload choices have the same problem. Since there
are going to be no solutions, choice declaration could
be supplied to `invalid ref` diagnostic directly.

Resolves: rdar://problem/50467583
Resolves: rdar://problem/50682022
Resolves: rdar://problem/50909555
2019-05-20 17:29:15 -07:00
Pavel Yaskevich
ce61dfeadf [Diagnostics] NFC: Couple of small cleanups for invalid member ref 2019-05-20 13:22:33 -07:00
Pavel Yaskevich
1499811add [Diagnostics] Fix incorrect metatype check which leads to crashes
Incorrect member reference diagnostic tailed for protocols
should cover existential metatypes as well.

rdar://problem/50679161
2019-05-20 12:52:53 -07:00
Pavel Yaskevich
e76ae9c343 [ConstraintSystem] Use missing protocol fix for sequence element mismatches related to protocols 2019-05-17 14:32:04 -07:00
Pavel Yaskevich
17643a30e0 [ConstraintSystem] Move missing contextual protocol detection to matchExistentialTypes 2019-05-17 12:53:27 -07:00
Pavel Yaskevich
ada6ab599a [ConstraintSystem] Use missing conformance fix to diagnose contextual failures
Extend use of `missing protocol conformance` fix to cover contextual
failures, such as:

- Assignment mismatches, where destination requires source to conform
  to certain protocol (or protocol composition);
- Incorrect returns where returned type doesn't conform to the
  protocol specified in the signature.
2019-05-17 12:53:22 -07:00
Pavel Yaskevich
d4e8d583ae Revert "[ConstraintSystem] Use missing conformance fix to diagnose contextual failures" 2019-05-17 12:45:55 -07:00
Pavel Yaskevich
5fb3a8ba30 Merge pull request #24754 from xedin/diag-missing-contextual-conformances
[ConstraintSystem] Use `missing conformance` fix to diagnose contextual failures
2019-05-17 11:40:49 -07:00
Hamish Knight
894a1e50bf [CS] Consolidate logic forming locators to callees
This commit adds `ConstraintSystem::getCalleeLocator`, which forms a
locator that describes the callee of a given expression. This function
is then used to replace various places where this logic is duplicated.

This commit also changes the conditions under which a ConstructorMember
callee locator is formed. Previously it was formed for a CallExpr with a
TypeExpr function expr. However, now such a locator is formed if the
function expr is of AnyMetatypeType. This allows it to be more lenient
with invalid code, as well as work with DotSelfExpr.

Resolves SR-10694.
2019-05-16 12:07:40 +01:00
Pavel Yaskevich
d5c561b44e [ConstraintSystem] Move missing contextual protocol detection to matchExistentialTypes 2019-05-15 15:37:36 -07:00
Pavel Yaskevich
577e6291a6 [ConstraintSystem] Use missing conformance fix to diagnose contextual failures
Extend use of `missing protocol conformance` fix to cover contextual
failures, such as:

- Assignment mismatches, where destination requires source to conform
  to certain protocol (or protocol composition);
- Incorrect returns where returned type doesn't conform to the
  protocol specified in the signature.
2019-05-15 14:49:17 -07:00
Pavel Yaskevich
1cc6f774a1 [ConstraintSystem] Improve contextual mismatch diagnostics for for ... in <expr> loop 2019-05-15 14:34:24 -07:00
Pavel Yaskevich
b9a0ca6afb [ConstraintSystem] Detect and diagnose conversion failures related to collection element types
Detect and diagnose a contextual mismatch between expected
collection element type and the one provided (e.g. source
of the assignment or argument to a call) e.g.:

```swift
let _: [Int] = ["hello"]

func foo(_: [Int]) {}
foo(["hello"])
```
2019-05-14 17:33:11 -07:00
Sam Lazarus
3d432fea65 Sema / Test: Fix misplaced fix-it for .init calls on instances 2019-05-09 19:17:39 -04:00
Sam Lazarus
2309ee580a Merge pull request #24617 from sl/sl/sr-10297
Add a Diagnostic for .init calls which should be transformed into assignments (SR-10297)
2019-05-09 18:05:38 -04:00
Sam Lazarus
8ad51b298e Sema: Get constraint locator for TupleExpr inside ApplyExpr branch
Additionally has some other minor cleanup.
2019-05-09 11:58:28 -04:00
Pavel Yaskevich
ce406fca04 Merge pull request #24615 from xedin/fix-autoclj-returning-fn-type
[ConstraintSystem] Allow arguments to be passed by value to `@autoclo…
2019-05-09 00:48:53 -07:00
Sam Lazarus
743d8fb0ee Sema: Change isImmutable to isMutable (thanks De Morgan) and negated call 2019-05-08 23:49:58 -04:00
Sam Lazarus
c498f38e5f Sema: Changed name of isInsideCall to isCallArgument and formatted changes 2019-05-08 23:44:29 -04:00
Sam Lazarus
edd8f70330 Sema: Change the diagnostic to choices made by the constraint system 2019-05-08 23:37:51 -04:00
Pavel Yaskevich
860cddfd34 [ConstraintSystem] Allow arguments to be passed by value to @autoclosure parameters
Instead of always requiring a call to be made to pass argument
to `@autoclosure` parameter, it should be allowed to pass argument
by value to `@autoclosure` parameter which can return a function
type.

```swift
func foo<T>(_ fn: @autoclosure () -> T) {}
func bar(_ fn: @autoclosure @escaping () -> Int) { foo(fn) }
```
2019-05-08 19:41:35 -07:00
Sam Lazarus
ad38117427 Sema: Add a diagnostic for attemting .init call on mutable value 2019-05-08 15:42:14 -04:00
Slava Pestov
7d96de54e8 Merge pull request #24601 from slavapestov/remove-old-inout-expr-check
Remove MiscDiagnostics diagnosis of invalid InOutExprs
2019-05-08 08:11:44 -04:00
Slava Pestov
b6985acc23 Sema: More flexible InvalidUseOfAddressOf 2019-05-07 23:10:48 -04:00
Pavel Yaskevich
cb3252e055 [ConstraintSystem] Extend use of missing explicit call fix
Now covers following new areas (alongside simple assignments):

- Contextual type coercions:
  - In assignment e.g. `let _: X = foo`
  - In return type positions e.g. `func foo() -> A { return bar }`

- Argument-to-parameter applications (including @autoclosure)
2019-05-07 16:41:19 -07:00
Pavel Yaskevich
4f63c4af71 [ConstraintSystem] Detect and diagnose extraneous returns from void functions
Diagnose an attempt return something from a function which
doesn't have a return type specified e.g.

```swift
func foo() { return 42 }
```
2019-05-07 13:43:14 -07:00
Pavel Yaskevich
6cd476be47 Merge pull request #24522 from xedin/diag-extraneous-addr-of
[ConstraintSystem] Detect and fix extraneous use of `&`
2019-05-06 13:56:04 -07:00
Pavel Yaskevich
3af163a94c [ConstraintSystem] Detect and fix extraneous use of &
Diagnose extraneous use of address of (`&`) which could only be
associated with arguments to `inout` parameters e.g.

```swift
struct S {}

var a: S = ...
var b: S = ...

a = &b
```
2019-05-06 11:18:47 -07:00
Sam Lazarus
4fac0b31c8 Merge pull request #24450 from sl/sl/sr-10202
Add useful diagnostic when trying to write through key path on private(set) var
2019-05-06 13:09:22 -04:00
Sam Lazarus
501cd91d10 Sema: Add additional assertion before providing keypath application diagnostic 2019-05-06 11:57:11 -04:00
Pavel Yaskevich
43526d031c Merge pull request #24431 from xedin/diag-noescape-param-assignment
[ConstraintSystem] Improve @escaping parameter diagnostics
2019-05-04 20:09:31 -07:00
Sam Lazarus
ed3eaef179 Sema / Test: Revert the error for assignment through read-only key path
This updates the error message so that in the case where we can find a
Decl, it gives the error "cannot assign through subscript: 'name' is a
read-only key path", and in the case where there's no associated Decl, gives the
error message "cannot assign through subscript: key path is read-only".

Additionally updates tests with the new error messages and formats all changes.
2019-05-04 14:03:06 -04:00
Sam Lazarus
6a7c378cbf Sema: Move getting key-path argument logic to a closure 2019-05-03 22:16:56 -04:00
Sam Lazarus
2f94a2132e Sema: Change cast to use dyn_cast instead of dyn_cast_or_null 2019-05-03 22:16:56 -04:00
Sam Lazarus
1a1e77077a Test / Sema: Change the wording of assignment through read-only key path error 2019-05-03 22:16:56 -04:00
Sam Lazarus
1d22e987c8 Sema: Add a diagnostic for assigning using a subscript with a read-only keypath 2019-05-03 22:16:56 -04:00