Commit Graph

1064 Commits

Author SHA1 Message Date
Holly Borla
173e4526ee [Diagnostics] Adjust wording of type_cannot_conform error message. 2019-09-16 14:55:38 -07:00
Hamish Knight
09431763fe Fix comment 2019-09-15 22:00:28 +01:00
Hamish Knight
176969ddde [CS] Allow simplification of key path subscript arg locators
This allows a few fixes to properly emit
diagnostics for key path subscript argument
contextual failures.

Resolves SR-11476.
2019-09-15 21:39:32 +01:00
Pavel Yaskevich
b898eaf326 [Diagnostics] Tailored diagnostics for reference equality operator mismatches 2019-09-13 22:35:52 -07:00
Pavel Yaskevich
973d58d56f [Diagnostics] Provide a tailored diagnostic for operator mismatch on missing conformance
If missing conformance is between two stdlib defined types which
are used in operator invocation, let's produce a generic diagnostic
about operator reference and a note about missing conformance.
2019-09-13 22:35:52 -07:00
Pavel Yaskevich
8a4fcaa4ba [Diagnostics] Don't diagnoses missing Equatable in pattern-matching of invalid expressions
If expression is incorrect it most likely wouldn't be able to satisfy
`Equatable` or other requirements of `~=` operator overloads, but
at the same time the main problem is related to `case` expression
itself so let's not diagnose missing conformances.
2019-09-13 22:35:52 -07:00
Pavel Yaskevich
015129cb36 [Diagnostics] Allow requirement failure to diagnose operators
In absence of general argument conversion failures requirement
errors associated with operators couldn't be diagnosed properly,
now this restriction could be lifted.
2019-09-13 22:35:51 -07:00
Pavel Yaskevich
93b39c9c23 [Diagnostics] Port pattern-matching mismatch diagnostic
Port diagnostics associated with implicit use of `~=` operator
which is used in `case` statements.
2019-09-13 22:35:50 -07:00
Pavel Yaskevich
1a57fc403a [ConstraintSystem] Make sure that l-value is preserved in argument positions
There is logic in `matchTypes` which would unwrap l-value if other
type is not an `inout`, which is not great for cases where parameter
type is a pointer and argument is an l-value which requires explicit
`&` to be converted.
2019-09-13 22:35:50 -07:00
Pavel Yaskevich
6d5cf3e43d [Diagnostics] Attempt fix-its appropriate for types in argument positions
Most of the fix-its associated with contextual failures are also
appropriate for argument-to-parameter conversion mismatches.
2019-09-13 22:35:50 -07:00
Pavel Yaskevich
e06cd0bd6f [Diagnostics] Tailored diagnostic when argument/parameter mismatch is due to missing conformance 2019-09-13 22:35:50 -07:00
Pavel Yaskevich
65c966ba16 [Diagnostics] Port a custom diagnostic for archetype mismatch in argument position 2019-09-13 22:35:50 -07:00
Pavel Yaskevich
dfc938bde7 [Diagnostics] Add a tailored diagnostic for attempt to use optional as a Bool in argument position 2019-09-13 22:35:50 -07:00
Pavel Yaskevich
34a12aa30e [Diagnostics] Add generic argument-to-parameter conversion failure
No specialized diagnostics yet, just a basic infrastructure to
produce generic a `cannot convert X to expected argument type Y`
message.
2019-09-13 22:35:50 -07:00
Holly Borla
40985b6eb7 [Diagnostics] Generalize the "protocol type cannot conform" error to
work for all types that cannot conform to protocols.
2019-09-13 14:51:17 -07:00
Sasha Krassovsky
8cae17ceac Fix warnings in Sema 2019-09-13 09:57:48 -07:00
Hamish Knight
c745c17c38 Revert naming changes to getCalleeLocator & getChoiceFor
In addition, add a document comment to `getCalleeLocator` to clarify
its semantics.
2019-09-09 22:08:52 +01:00
Hamish Knight
dba850f16c [CSDiagnostics] Use getAnchormostCalleeLocator
Have FailureDiagnostic::getChoiceFor take a ConstraintLocator argument
which is passed through to getAnchormostCalleeLocator, and rename to
getAnchormostChoiceFor to make the semantics clear. In addition, add
a convenience getAnchormostChoice member for the common case of getting
the choice for the anchor of the failure's locator.

This change means we can now resolve callees for failures associated
with key path subscript components.

Resolves SR-11435.
2019-09-09 14:14:35 +01:00
Hamish Knight
67ee821123 [CS] Allow getCalleeLocator to find key path component callees
In order to do this we need it to take a ConstraintLocator argument so
we can tell which component we want the callee for. To make it clear
that we're looking for a callee at the anchor, also rename the member
to getAnchormostCalleeLocator.
2019-09-09 14:14:35 +01:00
Hamish Knight
a407b1309f [CS] Allow getCalleeLocator to look through optional chaining (#27053)
[CS] Allow getCalleeLocator to look through optional chaining
2019-09-06 20:41:31 +01:00
Jordan Rose
94f1d2c159 Merge pull request #26612 from owenv/formatted_fixits
[Diagnostics][NFCI] Introduce Structured fix-its
2019-09-05 17:51:42 -07:00
Suyash Srijan
5cbfeb7b83 Merge pull request #27026 from theblixguy/fix/SR--11412
[CSDiagnostics] Offer protocol conformance fix-it in ContextualFailure
2019-09-06 00:44:38 +01:00
Suyash Srijan
f16d0e2782 [CSDiagnostics] Use join() directly and remove the if/else 2019-09-05 23:30:19 +01:00
Hamish Knight
dc8216e3f1 [CSDiagnostics] Update shouldHaveDirectCalleeOverload
Given we can now find overloads for applies of optional functions,
adjust the logic so we look at the call's direct callee. In addition,
tweak the logic so we don't assert on a ForceTryExpr.
2019-09-05 22:25:25 +01:00
Hamish Knight
8e0ec8df66 [CS] Allow getCalleeLocator to look through optional chaining 2019-09-05 22:25:25 +01:00
Holly Borla
7277f4f4ed [Diagnostics] Extend the AllowInOutConversion fix to cover inout attribute
mismatches in function types.

This improves the diagnostic in cases where we have argument-to-parameter
conversion failures or contextual type mismatches due to inout attribute
mismatches.
2019-09-05 14:16:24 -07:00
Suyash Srijan
c7088ffd41 [CSDiagnostics] Small cleanup in tryProtocolConformanceFixIt() 2019-09-05 21:11:17 +01:00
Suyash Srijan
5a1f06a1ef [CSDiagnostics] Use the existential layout to get the protocols 2019-09-05 21:05:32 +01:00
Suyash Srijan
666c000607 [CSDiagnostics] Use getExistentialLayout() to check if we need a class 2019-09-05 20:59:03 +01:00
Owen Voorhees
68e6065c8e [Diagnostics][NFC] Introduce Structured fix-its
These are defined with macros like errors/warnings/notes, and
make use of format strings and diagnostic arguments. The intent
is to leverage diagnostic arguments in the future to disambiguate
ambiguously spelled types.

Ported a few miscellaneous fix-its to the new system
2019-09-05 10:43:25 -07:00
Suyash Srijan
ab1184208a [CSDiagnostics] Offer a fix-it to conform the decl context to the missing protocols during contextual failure 2019-09-05 02:50:24 +01:00
Hamish Knight
fdbc21911b [CS] Don't create new locator when simplifying to anchor
We can directly use the version of `simplifyLocator` that works on
an anchor and path array ref instead.
2019-09-02 18:09:47 +01:00
Suyash Srijan
bd53fe355d Revert "[CS] Don't crash when default argument is magic literal and types don't match" 2019-08-31 00:54:37 +01:00
Pavel Yaskevich
b9cf4fa6c2 [Diagnostics] Add a diagnostic for invalid conversion of inout argument/parameter
Since there is no subtyping allowed in `inout` positions, let's
produce a tailored error message and a note about that.
2019-08-28 12:19:02 -07:00
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