Commit Graph

1119 Commits

Author SHA1 Message Date
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
65c966ba16 [Diagnostics] Port a custom diagnostic for archetype mismatch in argument position 2019-09-13 22:35:50 -07:00
Pavel Yaskevich
9d84aab2d5 [ConstraintSystem] Score generic argument-to-parameter mismatch fixes down
Since this is the most generic failure, we need to make sure that
it doesn't interfere with other more specific fixes.
2019-09-13 22:35:50 -07:00
Pavel Yaskevich
f28e674395 [Diagnostics] Detect situation when argument would match if it wasn't optional 2019-09-13 22:35:50 -07:00
Pavel Yaskevich
0f24f7e05a [CSFix] Introduce a fix for argument-to-parameter conversion mismatch 2019-09-13 22:35:50 -07:00
Sasha Krassovsky
8cae17ceac Fix warnings in Sema 2019-09-13 09:57:48 -07:00
Slava Pestov
cd8fddd2df Merge pull request #27145 from slavapestov/refactor-type-check-checked-cast
Refactor typeCheckCheckedCast() and a few other things
2019-09-12 21:07:07 -04:00
Holly Borla
0434d58ff0 Merge pull request #27123 from hborla/missing-conformance-diag
[ConstraintSystem] Allow fixing missing conformance failures for `Void` and uninhabited types.
2019-09-12 17:41:19 -07:00
Slava Pestov
de4b63defc Sema: Refactor typeCheckCheckedCast() a bit
This removes all calls to typesSatisfyConstraint() except for the
isConvertibleTo() check at the beginning, in the process making the
analysis a little bit more accurate.
2019-09-12 16:37:53 -04:00
Doug Gregor
7882a97066 Merge pull request #27127 from DougGregor/dynamic-member-lookup-iwb-crash
[Type checker] Fix a crash triggered from index-while-building.
2019-09-11 20:51:51 -07:00
Doug Gregor
7151d0e3d7 [Type checker] Fix a crash triggered from index-while-building. 2019-09-11 14:28:35 -07:00
Holly Borla
b9367d10cf [ConstraintSystem] Allow fixing missing conformance failures for
`Void` and uninhabited types.
2019-09-11 12:10:19 -07:00
Hamish Knight
dafcaeb5eb [CS] Simplify getCalleeDeclAndArgs
Now that we associate argument labels for key path
subscript components, remove the special logic for
it. In addition, we can now search for callees
directly by using `getCalleeLocator`, as it should
now be able to find all the correct callees that
`getCalleeDeclAndArgs` does.

By using `getCalleeLocator`, we now also correctly
resolve callees for operator calls, meaning that
we can now use them with function builders. In
addition, we no longer incorrectly resolve callees
for calls made on SubscriptExprs.

Resolves SR-11439 & SR-11440.
2019-09-10 12:06:35 +01:00
Holly Borla
d1f139c345 Merge pull request #27043 from hborla/inout-attr-mismatch-diag
[Diagnostics] Extend the `AllowInOutConversion` fix to cover inout attribute mismatches in function types.
2019-09-05 15:14:46 -07: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
Slava Pestov
22cb6f1176 AST: Introduce ProtocolDecl::get{AssociatedType,ProtocolRequirement}() 2019-09-03 22:39:35 -04:00
Pavel Yaskevich
5291ffb919 Merge pull request #26996 from xedin/extend-use-of-invalid-generic-param
[ConstraintSystem] Extend `generic argument mismatch` fix to all pointer conversions
2019-09-03 15:06:36 -07:00
Pavel Yaskevich
e9aa04a91a [ConstraintSystem] Extend generic argument mismatch fix to all pointer conversions
This makes it possible to diagnose all implicit pointer
conversions in argument positions with a better error
message which preserves enclosing types, and allows to
share base type matching logic across all pointer conversions.
2019-09-02 19:08:00 -07: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
c16b888004 Merge pull request #26941 from xedin/req-failures-with-any
[Diagnostics] Treat type requirement failures associated with `Self` …
2019-08-30 12:30:09 -07:00
Suyash Srijan
9121f45256 Merge pull request #26944 from theblixguy/fix/SR-11394
[CSDiagnostics] Fix a crasher in MissingContextualConformanceFailure
2019-08-30 07:53:31 +01:00
Suyash Srijan
3eea861bbe [CSSimplify] Return failure if there are no elements in the path and the anchor does not point towards an AssignExpr 2019-08-30 01:48:44 +01:00
Suyash Srijan
86807acaa8 [CSSimplify] If the locator path is empty, then return failure 2019-08-30 00:38:34 +01:00
Pavel Yaskevich
ecf8146938 [Diagnostics] Treat type requirement failures associated with Self = Any as unrelated
This helps us to filter out cases like operator overloads where
`Self` type comes from e.g. default for collection element -
`[1, "hello"].map { $0 + 1 }`. Main problem here is that
collection type couldn't be determined without unification to
`Any` and `+` failing for all numeric overloads is just a consequence.
2019-08-29 15:27:29 -07:00
Pavel Yaskevich
844fedaaec [ConstraintSystem] Introduce a fix to allow conversion between inout types
If there is an argument-to-parameter conversion which is associated with
`inout` parameter, subtyping is now permitted, types have to be identical.

```swift
protocol P {}
struct S : P  {}

func foo(_: inout P) {}

var s = S()
foo(&s) // `s` has to be defined as `P` e.g. `var s: P = S()`
        // to be used as an argument to `inout P` parameter.
```
2019-08-28 00:56:09 -07:00
Pavel Yaskevich
7b8fb88eb9 Merge pull request #26852 from xedin/refactor-treat-r-as-l-value
[ConstraintSystem] Be more principled about recording r-value -> l-value fix
2019-08-28 00:13:55 -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
Pavel Yaskevich
1b397ed486 [ConstraintSystem] Be more principled about recording r-value -> l-value fix
Instead of recording `TreatRValueAsLValue` fix directly inside
`matchTypes`, let's move towards recording it specifically for
each possible case in `repairFailures` which makes it a lot
easier to determine what other fixes could be applied (if any).
2019-08-27 13:13:28 -07:00
swift-ci
9a5d6fea35 Merge pull request #26872 from DougGregor/circular-inheritance-spin 2019-08-27 11:54:56 -07:00
Doug Gregor
1ee6d8139a [Constraint solver] Cope with circular inheritance.
This loop in the constraint solver won't terminate when given
ill-formed code involving circular inheritance. Make it
terminate. Fixes rdar://problem/54296278.
2019-08-27 10:29:36 -07:00
Dan Zheng
f44064cbbc [SE-0253] Introduce callables. (#24299)
Introduce callables: values of types that declare `func callAsFunction`
methods can be called like functions. The call syntax is shorthand for
applying `func callAsFunction` methods.

```swift
struct Adder {
  var base: Int
  func callAsFunction(_ x: Int) -> Int {
    return x + base
  }
}
var adder = Adder(base: 3)
adder(10) // desugars to `adder.callAsFunction(10)`
```

`func callAsFunction` argument labels are required at call sites.
Multiple `func callAsFunction` methods on a single type are supported.
`mutating func callAsFunction` is supported.

SR-11378 tracks improving `callAsFunction` diagnostics.
2019-08-26 23:56:36 -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
8afc560708 [ConstraintSystem] Introduce a notion of a "hole"
A "hole" is a type variable which type couldn't be determined
due to an inference failure e.g. missing member, ambiguous generic
parameter which hasn't been explicitly specified.

It is used to propagate information about failures and avoid
recording fixes which are a consequence of earlier failures e.g.

```swift
func foo<T: BinaryInteger>(_: T) {}

struct S {}

foo(S.bar) // Actual failure here is that `S` doesn't have a member
           // `bar` but a consequence of that failure is that generic
           // parameter `T` doesn't conform to `BinaryInteger`.
```
2019-08-22 17:24:45 -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
swift-ci
fb9a864237 Merge pull request #26765 from amartini51/master 2019-08-21 13:21:01 -07:00
Pavel Yaskevich
cfaecfc015 Merge pull request #26755 from xedin/port-throws-contextual-mismatch
[Diagnostics] Port tailored contextual diagnostic when thrown type do…
2019-08-21 11:03:05 -07:00
Alex Martini
f040edaa85 Typo fix: of of -> of
rdar://problem/54218099
2019-08-21 10:40:18 -07:00
Doug Gregor
c234b095ca Merge pull request #26749 from DougGregor/key-path-extra-type-variables
[Constraint solver] Tie together all of the type variables in a key path
2019-08-21 06:53:02 -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
84d7b60a99 Merge pull request #26751 from xedin/nil-contextual-failures
[Diagnostics] Port contextual mismatches involving `nil` to new frame…
2019-08-20 15:29:37 -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
0cb7364421 Merge pull request #26725 from xedin/fix-req-regressions
[Diagnostics] Lift all restrictions from `invalid generic arguments` …
2019-08-20 12:28:07 -07:00
Doug Gregor
562ed4d999 [Constraint solver] Tie together all of the type variables in a key path.
This is a workaround for rdar://problem/54322807 that should limit the
expansion in the number of constraint scopes visited.
2019-08-20 11:11:07 -07:00
Holly Borla
0cdfda0eb9 Merge pull request #26541 from hborla/autoclosure-optional-ptr-conversion-diag
[Diagnostics] Improve the diagnostic for invalid optional pointer conversions for an autoclosure result type.
2019-08-20 10:58:33 -07:00
Pavel Yaskevich
589ebac1b2 [Diagnostics] Lift all restrictions from invalid generic arguments fix expect to optional types
This helps us to better diagnose failures related to generic
requirements like `T == [Int]` as well as protocol compositions,
which require deep equality check.
2019-08-20 10:50:17 -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
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
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