Commit Graph

1357 Commits

Author SHA1 Message Date
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
Pavel Yaskevich
d4e8d583ae Revert "[ConstraintSystem] Use missing conformance fix to diagnose contextual failures" 2019-05-17 12:45:55 -07:00
Pavel Yaskevich
5fb3a8ba30 Merge pull request #24754 from xedin/diag-missing-contextual-conformances
[ConstraintSystem] Use `missing conformance` fix to diagnose contextual failures
2019-05-17 11:40:49 -07:00
Hamish Knight
f4c0bc748a [Sema] Fix compiler crasher SR-10696 2019-05-16 12:07:42 +01:00
Hamish Knight
8aa7401ba5 [Sema] Add getDeclOrNull to OverloadChoice
This helps clean up a bunch of call sites.
2019-05-16 12:07:41 +01:00
Pavel Yaskevich
d5c561b44e [ConstraintSystem] Move missing contextual protocol detection to matchExistentialTypes 2019-05-15 15:37:36 -07:00
Pavel Yaskevich
577e6291a6 [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-15 14:49:17 -07:00
Slava Pestov
6e3609dc22 AST: ProtocolConformanceRef::getTypeWitnessByName() should be an instance method 2019-05-14 19:28:55 -04:00
Slava Pestov
644b6adcd2 AST: Simplify ProtocolConformanceRef::getTypeWitnessByName() 2019-05-10 15:00:48 -04:00
Pavel Yaskevich
62b2da803c [ConstraintSystem] Improve @escaping parameter diagnostics
Detect difference in escapiness while matching function types
in the solver and record a fix that suggests to add @escaping
attribute where appropriate.

Also emit a tailored diagnostic when non-escaping parameter
type is used as a type of a generic parameter.
2019-05-02 00:40:30 -07:00
Doug Gregor
a1af0e45cb [Constraint solver] Reject trailing closures matching non-closure-parameters.
Enhance call-argument matching to reject trailing closures that match up
with parameters that cannot accept closures at all.

Fixes rdar://problem/50362170.
2019-04-30 23:12:32 -07:00
Nate Chandler
0143ce25c2 Implicitly convert single exprs from uninhabited.
When type-checking a return statement's result, pass a new
ContextualTypePurpose when that return statement appears in a function
with a single expression.  When solving the corresponding constraint
system, the conversion constraint will have a new ConstraintKind.  When
matching types, check whether the constraint kind is this new kind,
meaning that the constraint is between a function's single expression
and the function's result.  If it is, allow a conversion from
an uninhabited type (the expression's type) to anything (the function's
result type) by adding an uninhabited upcast restriction to the vector
of conversions.  Finally, at coercion time, upon encountering this
restriction, call coerceUninhabited, replacing the original expression
with an UninhabitedUpcastExpr.  Finally, at SILGen time, treat this
UninhabitedUpcastExpr as a ForcedCheckedCastExpr.

Eliminates the bare ConstraintSystem usage from
typeCheckFunctionBodyUntil, ensuring that the same code path is followed
for all function bodies.
2019-04-24 10:04:17 -07:00
Slava Pestov
eed84abda9 Sema: Add TVO_CanBindToNoEscape
We have a systemic class of issues where noescape types end up bound to
type variables in places that should not. The existing diagnostic for
this is ad-hoc and duplicated in several places but it doesn't actually
address the root cause of the problem.

For now, I've changed all call sites of createTypeVariable() to set the
new flag. I plan on removing enough occurrences of the flag to replicate
the old diagnostics. Then we can continue to refine this over time.
2019-04-16 23:01:33 -04:00