Commit Graph

1236 Commits

Author SHA1 Message Date
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
Holly Borla
d299925ae3 [Diagnostics] Port the "extra address of agrument" diagnostic to the new
framework.
2019-08-16 11:55:11 -07: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
1ecd209e3b [CSDiag] Diagnose call expected no arguments without additional type-check 2019-08-13 11:55:08 -07:00
Pavel Yaskevich
9bbdf79db3 [CSDiag] NFC: Remove obsolete throws/no-escape contextual mismatch handling 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
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
e7bff97929 [Diagnostics] NFC: Temporarily move couple of auxiliary functions to ConstraintSystem
Functions like `isRawRepresentable*` and `conformsToKnownProtocol`
have to be be shared between CSDiag and new diagnostics framework
until relevant code is removed from the former.
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
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
Pavel Yaskevich
dc6f9e2229 Merge pull request #26488 from gregomni/sr-10000
[Typechecker][QoI] Calls with unexpected trailing closures weren't getting passed on to ArgumentMatcher
2019-08-05 09:49:05 -07:00
Greg Titus
f444b4d44b Calls with unexpected trailing closures weren't getting passed on to ArgumentMatcher. 2019-08-05 06:50:44 -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
Sam Lazarus
0fa9ec3c22 Diagnostics: Changed tuple mismatch fix constraint generation to use matchTupleTypes 2019-08-02 13:52:24 -04:00
Slava Pestov
d3f65e7b4b AST: Remove SubscriptDecl::isSettable() 2019-07-31 21:26:02 -04:00
Andrew Trick
c8a16d3d9b Merge pull request #26041 from atrick/remove-ptrcast-diag
Remove the Swift-3-era pointer casting diagnostic.
2019-07-30 09:59:00 -07:00
Sam Lazarus
a3b56c2790 Diagnostics: Ported tuple mismatch diagnostic to new diagnostic framework 2019-07-29 13:45:08 -04:00
Pavel Yaskevich
effd0d00c6 Merge pull request #26302 from xedin/remove-label-mismatch-from-lookup
[Diagnostics] Don't filter overload set candidates based on labels in lookup
2019-07-26 10:34:23 -07:00
Pavel Yaskevich
44f82f256f [TypeChecker] Adjust some of tests improved/regressed after removal of UR_LabelMismatch 2019-07-25 00:36:00 -07:00
Pavel Yaskevich
d3205b202e [ConstraintSystem] Remove UR_LabelMismatch overload unavailability reason
This helps with:

- Diagnostics because solver would get more choices to work with
  in diagnostic mode;
- Avoid adding the same overload multiple times
  (retry after label mismatch and no viable candidates);
- Unify overload handling/filtering in `simplfyAppliedOverloads`.
2019-07-25 00:36:00 -07:00
Doug Gregor
8355f3d270 [Constraint graph] Move constraint uniquing into gatherConstraints().
Simplify the interface to gatherConstraints() by performing the
uniquing within the function itself and returning only the resulting
(uniqued) vector of constraints.
2019-07-25 02:26:49 -04:00
Pavel Yaskevich
5fe29a719b Merge pull request #26219 from theblixguy/fix/SR-11060
[CSDiag] Add a new diagnostic for @propertyWrapper implicit init call missing arguments
2019-07-19 09:45:37 -07:00
Suyash Srijan
ab1f059e8b [CSDiag] Simplify the 'isPropertyWrapperImplicitInit' method a bit 2019-07-19 00:48:36 +01:00
Suyash Srijan
b36f772a6b [CSDiag] Check if TypeExpr has type and a nominal decl 2019-07-19 00:39:07 +01:00
Suyash Srijan
c1c4ca5e0a [CSDiag] Simplify the code for checking if the type is a propertyWrapper 2019-07-18 23:14:31 +01:00
Suyash Srijan
f47f5c44e4 [CSDiag] Adds a new diagnostic for implicit propertyWrapper initializer 2019-07-18 23:06:03 +01:00
Suyash Srijan
5e528de547 [CSDiag] We don't need the property wrapper info 2019-07-18 22:01:38 +01:00
Suyash Srijan
a3b6ac555c [CSDiag] Check for property wrapper implicit init when creating fix-it 2019-07-18 21:30:33 +01:00
Pavel Yaskevich
aaae13e48b [CSDiag] NFC: Remove obsolete diagnoseTupleParameterMismatch 2019-07-16 11:06:42 -07:00
Pavel Yaskevich
9550d10037 [Diagnostics] Add a diagnostic for single parameter tuple splat
Diagnose situation when a single "tuple" parameter is given N arguments e.g.

```swift
func foo<T>(_ x: (T, Bool)) {}
foo(1, false) // foo exptects a single argument of tuple type `(1, false)`
```
2019-07-16 11:06:42 -07:00
Andrew Trick
d2a0ae29d3 Remove the Swift-3-era pointer casting diagnostic.
Remove this additional note when attempting to incorrectly initialize UnsafePointer:

  Pointer conversion restricted: use '.assumingMemoryBound(to:)' or
  '.bindMemory(to:capacity:)' to view memory as a type.

The note was added for Swift 3 migration. The idea was to get projects
building as quickly as possible and effectively tag bad behavior so it
could be corrected later. That worked, but now it's been working
against us for the past couple of releases. Too much new code is using
these two APIs and the vast majority of uses are not only incorrect,
but much more simply expressed without them. Instead, programmers need
to be made aware that the UnsafeRawBufferPointer API already does what
they want... but we can work on that problem as separate task.

Most uses of these APIs are something like:

  return rawptr.assumingMemoryBound(to: T.self).pointee

or

  UnsafeRawPointer(ptr).bindMemory(to: UInt16.self, capacity: 2).pointee

Instead of simply

  return rawptr.load(as: T.self)

I've even seen programmers do this:

  extension UnsafeRawPointer {
    var uint8: UInt8 {
      let uint8Ptr = self.bindMemory( to: UInt8.self, capacity: 1 )
      return uint8Ptr[0]
    }
  }

...instead of simply using either UnsafeRawPointer.load or UnsafeRawBufferPointer's subscript.
2019-07-09 15:47:22 -07:00
Pavel Yaskevich
24048262dd [CSDiag] Remove obsolete logic related to invalid mutating member refs 2019-07-09 00:25:30 -07:00
Pavel Yaskevich
a2652ea8e1 [Diagnostics] NFC: Move logic related to member ref on optional without unwrap to new framework
Since there is already a diagnostic for this `MemberAccessOnOptionalBaseFailure`
it should incorporate all related diagnostic logic and could be used from CSDiag.
2019-07-02 16:00:36 -07:00
Greg Titus
707667186e Merge pull request #25903 from gregomni/sr-10670
[Diagnostics] Cleanup and fix for incorrect 'type(of:)' suggestion on initializer
2019-07-01 07:37:44 -07:00
gregomni
921d1d7dbb Remove dead code: All the correct instances of these diagnostics are now handled by AllowTypeOrInstanceMemberFailure, leaving incorrect handling for init's with inout args, because the arg contains a LoadExpr. 2019-06-30 19:49:07 -07:00
Pavel Yaskevich
c118c383d8 [Diagnostics] Diagnose all invalid references to instance methods
Extend use of "instance member on type" fix to cover potentially
invalid partial applications, references to instance members on
metatypes, and remove related and now obsolete code from `CSDiag`.

Resolves: [SR-9415](https://bugs.swift.org/browse/SR-9415)
2019-06-27 16:09:07 -07:00
Jordan Rose
9e471e4124 Don't offer a fix-it to convert to a 'some' type (#25619)
There's no way to spell an opaque type in a cast, and that means
there's no way to force the conversion today (even if you know the
types are dynamically the same).

Part of rdar://problem/50346954
2019-06-19 19:17:32 -07:00
Hamish Knight
e1f8af2389 Merge remote-tracking branch 'upstream/master' into a-couple-of-tangents 2019-06-18 19:09:06 +01:00
Pavel Yaskevich
ef293a568a Merge pull request #25443 from xedin/rdar-50869732
[CSDiag] Always find and set correct declaration context for sub-expr…
2019-06-18 00:46:20 -07:00
Pavel Yaskevich
a5df786263 [CSDiag] Always find and set correct declaration context for sub-expression type-check
Replace dedicated method with `typeCheckChildIndependently` always
setting the closest possible declaration context for type-check call.
This fixes a problem where sub-expression comes from multiple levels
or nested closures but CSDiag didn't re-typecheck parent closure.

Resolves: rdar://problem/50869732
2019-06-17 15:09:32 -07:00
Parker Schuh
0b03721ce8 Convert DictionaryExpr to not use tc.callWitness() or generate a SemanticExpr.
For reference, everything else except string interpolation has been
migrated to this new form.
2019-06-13 15:58:03 -07:00
Hamish Knight
a3ead02902 Merge remote-tracking branch 'upstream/master' into a-couple-of-tangents 2019-06-13 14:46:55 +01:00
Pavel Yaskevich
735a884c06 Merge pull request #25383 from xedin/rdar-51641323
[ConstraintSystem] Replace special locator for return of single expr …
2019-06-12 16:25:41 -07:00
Pavel Yaskevich
ba6a5e10f8 [ConstraintSystem] Replace special locator for return of single expr function with a flag on contextual type locator
It's only needed in one place in the constraint solver to allow
`() -> T` to `() -> ()` and `() -> Never` to `() -> T` for expressions
representing return of a single expression functions, so to simplify
contextual type handling in diagnostic and other places it would be
better to replace dedicated locator kind with a flag on existing `ContextualType`.

Resolves: rdar://problem/51641323
2019-06-12 10:13:44 -07:00
Doug Gregor
0494574706 Factor the computation of default arguments into ParameterListInfo.
Provide a place where we can capture more information about the parameters
from a declaration being called.
2019-06-11 17:34:44 -07:00
Slava Pestov
c84aad8bf1 Sema: TypeChecker::conformsToProtocol() is static 2019-06-11 02:47:32 -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