Commit Graph

184 Commits

Author SHA1 Message Date
Hamish Knight
6c00d89a87 Assert when we expect to resolve a callee overload
This helps ensure we don't miss cases where `getChoiceFor` was meant to
return a callee overload but doesn't.
2019-06-13 13:51:51 +01:00
Hamish Knight
ebc2ff5bd5 Use getFunctionArgApplyInfo in missing-unwrap diagnostic 2019-06-13 13:51:50 +01:00
Hamish Knight
179c81d437 Use getFunctionArgApplyInfo in escaping diagnostics
This simplifies the implementation and fixes a compiler crasher.

Resolves SR-10811.
2019-06-13 13:51:49 +01:00
Hamish Knight
a84cdbc31e Add FailureDiagnostic::getFunctionArgApplyInfo
This allows failure diagnostics to retrieve information about the
application of an argument to a parameter at their locator.
2019-06-13 13:51:49 +01:00
Hamish Knight
061ab18297 Add FailureDiagnostic::resolveInterfaceType
This allows a raw type to be resolved using generic parameters where
possible.
2019-06-13 13:51:49 +01:00
Doug Gregor
f2db4078a5 [Type checker] Collapse some duplicate code. Thanks, Pavel! 2019-06-11 17:34:44 -07:00
Doug Gregor
b634f594a0 [Function builders] Create a FailureDiagnostic for unhandled constructs. 2019-06-11 17:34:44 -07:00
Pavel Yaskevich
4bd5a1e4e1 [Diagnostics] Clarify requirement failure source when it's anchored at assignment
While trying to fetch owner type for generic requirement failures
anchored at assignment expression, use assignment source as an anchor
because that's where requirements come from - conversion from source
type to destination.

Resolves: rdar://problem/51587755
2019-06-11 11:59:46 -07:00
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