Commit Graph

1319 Commits

Author SHA1 Message Date
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
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
Hamish Knight
dcabcb36b4 [AST][Sema] Add ValueDecl::hasCurriedSelf
Use this function to replace various places where the logic is
duplicated.

In addition, isolate the logic where subscripts are treated as having
curried self parameters to CalleeCandidateInfo, as their interface types
don't have a curried self, but get curried with self by
CalleeCandidateInfo. Ideally we'd fix this by having a subscript's
interface type be curried with self, but given that most of this CSDiag
logic should be going away, this may not be necessary.
2019-05-31 15:53:26 +01: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
facb2d8574 Sema / Test: Allow fallback to CSDiag still using the new diagnostic 2019-05-30 18:28:12 -04:00
Pavel Yaskevich
5e35c3e445 [Diagnostics] Replace CSDiag logic for diagnosing missing generic arguments with new diagnostic 2019-05-30 12:38:17 -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
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
7511e0a4d0 Merge pull request #24926 from xedin/rdar-50668864
[CSDiag] Adjust assert to account for changes in `filterContextualMem…
2019-05-20 16:30:59 -07:00
David Ungar
71228603b3 Remove dead code. 2019-05-20 14:53:35 -07:00
Pavel Yaskevich
31d001cc67 [CSDiag] Adjust assert to account for changes in filterContextualMemberList.
Originally `filterContextualMemberList` would only return a limited
set of closeness kinds `CC_GeneralMismatch`, `CC_Argument{Label, Count}Mismatch`,
and unavailable/inaccessible. At some point later it also started
matching almost everything besides `CC_SelfMismatch` and logic in
`visitUnresolvedMemberExpr` needs to get adjusted to account for that.

Resolves: rdar://problem/50668864
2019-05-20 13:39:39 -07:00
David Ungar
9681c3b0c8 Add isDecl check. 2019-05-20 13:04:30 -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