Commit Graph

1230 Commits

Author SHA1 Message Date
Pavel Yaskevich
d0530b996c Merge pull request #26798 from xedin/introduces-cs-holes
[ConstraintSystem] Introduce a notion of a "hole"
2019-08-27 15:54:01 -07:00
Hamish Knight
86995f732f [CSDiagnostics] Add a couple of asserts to RequirementFailure
This will make it slightly easier to spot cases where we've resolved
to the wrong affected decl.
2019-08-27 15:59:08 +01:00
Pavel Yaskevich
fbb55ce5bc [Diagnostics] Add a tailored diagnostic for no accessible initializers 2019-08-22 17:25:24 -07:00
Pavel Yaskevich
fa9c3f3a10 [ConstraintSystem] Track missing members via "holes"
Replace specialized `MissingMembers` tracking with more general
constraint system "holes" which simplifies solver logic.
2019-08-22 17:25:05 -07:00
Pavel Yaskevich
b813976fd1 [Diagnostics] Port diagnostic for CTP_YieldByReference
Last special case from `FailureDiagnosis::diagnoseContextualConversionError`
has been ported to the new diagnostic framework.
2019-08-21 13:47:39 -07:00
Pavel Yaskevich
8296b554f4 [Diagnostics] Port tailored contextual diagnostic when thrown type doesn't conform to Error
`throw` statements are type-checked as having contextual `Error`
type to make sure that thrown type conforms to `Error` protocol.
Let's make sure that's correctly handled by new diagnostics framework.

```swift
func foo() throws {
  throw 0 // `Int` doesn't conform to `Error` protocol.
}
```
2019-08-20 17:03:19 -07:00
Pavel Yaskevich
0a8f596736 [Diagnostics] Port contextual mismatches involving nil to new framework
Detect and diagnose contextual failures originating in an attempt
to convert `nil` to some other non-optional type e.g.

```swift
let _: Int = nil // can't initialize `Int` with `nil`

func foo() -> Int {
  return nil // can't return `nil` from `foo`
}

_ = 1 + nil // there is no `+` overload which accepts `Int` and optional
```
2019-08-20 14:23:54 -07:00
Pavel Yaskevich
98a54a1e73 Merge pull request #26297 from hamishknight/pass-by-value-by-name
[CS] Add specific accessors for path element info
2019-08-20 01:04:59 -07:00
Slava Pestov
80ccbe5116 AST: Stop passing around a LazyResolver in name lookup
Note that in all cases it was either nullptr or ctx.getLazyResolver().
While passing in nullptr might appear at first glance to mean something
("don't type check anything"), in practice we would check for a nullptr
value and pull out ctx.getLazyResolver() instead. Furthermore, with
the lazy resolver going away (at least for resolveDeclSignature() calls),
it won't make sense to do that anymore anyway.
2019-08-19 23:00:57 -04:00
Pavel Yaskevich
7ac754acc4 [Diagnostics] Transform incorrect generic arguments into a contexual mismatch
Since this kind of failure is really a conversion failure, let's
inherit from `Contextual{Mismatch, Failure}` which also helps with
storage for from/to types and their resolution.

Also let's use original types involved in conversion to form
this fix, which helps to perserve all of the original sugar.
2019-08-19 09:56:48 -07:00
Hamish Knight
6e45ef1347 [CS] Add locator find[First/Last] members
These members provide a convenient way of getting the first or last
occurrence of a given kind of element in a locator's path.
2019-08-19 11:58:50 +01:00
Hamish Knight
c225d52873 [CS] Add locator last element casting members
These members provide a convenient way of casting the last element of
a locator to a given path element type.
2019-08-19 11:58:50 +01:00
Hamish Knight
a0919f73b0 [CS] Use subclasses to expose locator element info
Instead of adding specific accessors directly to
ConstraintLocator::PathElement, add subclasses that expose these
accessors.
2019-08-19 11:58:49 +01:00
Hamish Knight
b5b41a5bbe [CS] Add specific accessors for path element info
This commit replaces the `getValue()` and `getValue2()` members on
`ConstraintLocator::PathElement` with specific accessors for each
expected path component kind. IMO this adds some clarity to the call
sites, especially for `getArgIdx()` and `getParamIdx()`.

In addition, this commit adds a private `getValue` member that can
access a value at a given index, which will make it easier to add a
third value in the future.
2019-08-19 11:58:49 +01:00
Pavel Yaskevich
fc3d9755fb Merge pull request #26677 from xedin/dedup-generic-requirements
[Diagnostics] Correctly identify location of requirement failure
2019-08-17 00:02:08 -07:00
Pavel Yaskevich
cbadd7ffc2 [Diagnostics] Correctly identify location of requirement failure
Previously in situations like:

```swift
protocol P {}

struct S<T: P> {
  var value: T
}

_ = S(value: 42)
```

Diagnostic has reported a problem as related to "reference" to `init`
but the failing generic type requirement belongs to `S`, so a
better diagnostic in such case should mention `generic struct S`.
2019-08-16 22:02:37 -07:00
Holly Borla
f88a016bba Merge pull request #26697 from hborla/extra-addr-of-arg-diag
[Diagnostics] Port the "extra address of argument" diagnostic to the new framework.
2019-08-16 19:33:57 -07:00
Holly Borla
cc1082146d [Diagnostics] Unify DiagnosticFailure and ConstraintFix classes for extra & failures.
Make `InvalidUseOfAddressOf` a `ContextualFailure`, make `ReturnAddressOf`
a `ContextualMismatch`, and extend this failure to cover using `&` with a
non-inout argument.
2019-08-16 17:43:59 -07:00
Holly Borla
d299925ae3 [Diagnostics] Port the "extra address of agrument" diagnostic to the new
framework.
2019-08-16 11:55:11 -07:00
Slava Pestov
19d283d9dc AST: Replace ImplicitlyUnwrappedOptionalAttr with Decl::{is,set}ImplicitlyUnwrappedOptional() 2019-08-15 18:41:41 -04:00
Pavel Yaskevich
253abad789 [Diagnostics] Port remaining contextual failures (expect associated with nil)
Remove the rest of the obsolete code from `diagnoseContextualConversionError`
and port diagnostic about string indexing to new diagnostic framework.
2019-08-13 14:33:38 -07:00
Pavel Yaskevich
15ae692da0 [ConstraintSystem] Repair and diagnose failures relared to throws mismatch
If the only difference between two functions is `throws` and it
is not a subtype relationship, let's repair the problem by dropping
`throws` attribute and letting solver continue to search for
a solution, which would later be diagnosed.
2019-08-13 11:55:08 -07:00
Pavel Yaskevich
290ec3c1cc [Diagnostics] Substring -> String fix-it should be anchored at semantic expressoin
If contextual failure is detected in sub-expression (through
type-check call via CSDiag), let's make sure that fix-it
is always anchored at semantic expression otherwise it could be
attached to the paren representing whole argument list.
2019-08-13 11:55:08 -07:00
Pavel Yaskevich
fd85bfe045 [Diagnostics] Port tailored diagnostic for dictionary conversions
Detect that contextual conversion is between a dictionary type
and an array type which comes form an array literal and produce
a tailored diagnostic.
2019-08-13 11:55:08 -07:00
Pavel Yaskevich
0e9f7c0bfc [Diagnostics] Diagnose thowing -> non-throwing contextual mismatch 2019-08-13 11:55:08 -07:00
Pavel Yaskevich
90e38af306 [Diagnostics] Port type coercion fix-it to contextual failure 2019-08-13 11:55:08 -07:00
Pavel Yaskevich
69589f01a6 [Diagnostics] Port integer cast fix-it to contextual failure 2019-08-13 11:55:08 -07:00
Pavel Yaskevich
27b9d37a82 [Diagnostics] Port raw representable fix-it to contextual failure 2019-08-13 11:55:08 -07:00
Pavel Yaskevich
fba0cfa2a2 [Diagnostics] Port tailored diagnostic for optional -> bool contextual conversion 2019-08-13 11:55:08 -07:00
Pavel Yaskevich
a4d7cbd794 [Diagnostics] Extend contextual failure diagnostic to support all basic mismatches 2019-08-13 11:55:08 -07:00
Pavel Yaskevich
075e92b182 Merge pull request #26576 from LucianoPAlmeida/SR-10597-name-lookup-failure-diagnostics
SR-10597 KeyPath dynamic member lookup
2019-08-12 18:00:45 -07:00
Luciano Almeida
1d910fb2bc Fix identation 2019-08-12 19:28:44 -03:00
Luciano Almeida
55907fbd0f Adding no corrections diagnostic for dynamic member 2019-08-12 19:25:38 -03:00
Luciano Almeida
a7b5f714e4 Apply diagnostic message suggestion 2019-08-09 23:47:42 -03:00
Luciano Almeida
df14698efd Merge branch 'SR-10597-name-lookup-failure-diagnostics' of https://github.com/LucianoPAlmeida/swift into SR-10597-name-lookup-failure-diagnostics 2019-08-09 23:39:30 -03:00
Luciano Almeida
6d40a96c0a Fixing identation 2019-08-09 23:39:25 -03:00
Luciano Almeida
a5db6bf0a5 Apply suggestions from code review
Co-Authored-By: Xiaodi Wu <xiaodi.wu@gmail.com>
2019-08-09 23:37:00 -03:00
Pavel Yaskevich
385fb0c665 [Diagnostics] Make force downcast fix contextual and move it to repairFailures
This way it covers a lot more ground and doesn't conflict with
other fixes.

Another notable change is related to check for IUO associated
with source type, that covers cases like:

```swift
func foo(_ v: NSString!) -> String {
  return v
}
```

Instead of general conversion failure check for IUO enables solver
to introduce force downcast fix.
2019-08-09 01:09:52 -07:00
Luciano Almeida
d55e1f6055 Adding diagnostic to fix SR-10597 2019-08-08 23:33:43 -03:00
Pavel Yaskevich
8ac2ef8611 [Diagnostics] Extend generic argument mismatch to cover [T] to Unsafe*Pointer<T> conversions
Example:

```swift
func foo(_ x: UnsafePointer<Int>) {}
var arr: [Float] = [0, 1, 2]
foo(&arr) // Cannot convert [Float] to UnsafePointer<Int> because of Float vs. Int
```
2019-08-07 13:16:20 -07:00
Pavel Yaskevich
a34fe9ae55 [Diagnostics] Extend missing & diagnostic to cover pointer conversions
Example:

```swift
func foo(_: UnsafePointer<Int>) {}

var x: Int = 0
foo(x) <- should suggest adding `&`
```
2019-08-06 17:52:24 -07:00
Holly Borla
caeb2a44a8 Merge pull request #26470 from hborla/autoclosure-pointer-conversion-diagnostic
[Diagnostics] Improve the diagnostic for invalid pointer conversion for an autoclosure result type.
2019-08-05 10:06:15 -07:00
Pavel Yaskevich
b148ea0a41 Merge pull request #26444 from xedin/diag-missing-call-with-defaults
[CSDiagnostics] Teach `missing explicit call` fix to account for defa…
2019-08-02 16:36:40 -07:00
Holly Borla
edcf4055d2 [Diagnostics] Use ContextualFailure and ContextualMistatch as base classes
for `AutoClosurePointerConversionFailure` and `AllowAutoClosurePointerConversion`
respectively.
2019-08-02 15:23:25 -07:00
Holly Borla
e76f5f1d0b [Diagnostics] Improve the diagnostic for invalid pointer conversion for an autoclosure result type.
Add constraint fix `AllowAutoClosurePointerConversion` and corresponding diagnostic
`AutoClosurePointerConversionFailure`. When we discover that we're trying to do an
inout-to-pointer conversion in `matchTypes`, add the constraint fix, which tries to do the
conversion as if the pointer type is a regular function argument.
2019-08-02 14:16:06 -07:00
Pavel Yaskevich
2cfcdf49dc Merge pull request #26391 from sl/port-tuple-assignment-diagnostic
[Diagnostics] Ported tuple mismatch diagnostic to new diagnostic framework
2019-08-02 13:22:52 -07:00
Slava Pestov
d3f65e7b4b AST: Remove SubscriptDecl::isSettable() 2019-07-31 21:26:02 -04:00
Pavel Yaskevich
5c82b57096 [CSDiagnostics] Teach missing explicit call fix to account for defaults
Currently we only produce a fix if function type doesn't have any
parameters, but it should also account for function having defaults
for all of its parameters which would still allow for nullary call.
2019-07-31 17:21:49 -07:00
Pavel Yaskevich
5744becc34 Merge pull request #26417 from theblixguy/fix/SR-11236
[CSDiagnostics] Fix a crasher in MissingGenericArgumentsFailure
2019-07-30 16:08:45 -07:00
Suyash Srijan
2339b5f9bd [CSDiagnostics] Move check inside getDeclContext() 2019-07-30 20:27:25 +01:00