Commit Graph

1248 Commits

Author SHA1 Message Date
Pavel Yaskevich
a7bc52fd9a Merge pull request #28197 from xedin/handle-single-pd-arg-mismatch
[Diagnostics] Produce a tailored diagnostic for property wrapper argu…
2019-11-11 15:13:56 -08:00
Pavel Yaskevich
08f8f4191d [Diagnostics] Produce a tailored diagnostic for property wrapper argument mismatch
Diagnose an attempt to initialize a property, which has a property
wrapper, with a value of an incorrect type.
2019-11-11 12:59:28 -08:00
Robert Widmann
7bad9aacc3 Drop the TypeChecker out of ConstraintSystem 2019-11-10 13:26:47 -08:00
Robert Widmann
1123b1f897 Move constraint satisfiability utilities 2019-11-10 13:12:50 -08:00
Pavel Yaskevich
ef98b39de9 Merge pull request #28141 from xedin/sr-8411
[TypeChecker] Disambiguite cases of implicit pointer conversions with…
2019-11-08 10:18:46 -08:00
Hamish Knight
f519505c8b Remove some more TypeChecker uses (#28132)
Remove some more TypeChecker uses
2019-11-07 17:56:45 -08:00
Pavel Yaskevich
3feb25c958 [TypeChecker] Disambiguite cases of implicit pointer conversions with optionals
Currently `{inout, array, string}-to-pointer` conversion doesn't
track whether there was a difference in optionality between involved
types which leads to ambiguity when different overload choices
have different optionality requirements.

Let's fix that by increasing a score in cases if pointer type
is itself optional e.g.:

```swift
func foo(_ x: UnsafeMutablePointer<Int>) {}
func foo(_ x: UnsafeMutablePointer<Int>?) {}

foo(&foo) // Should pick the least optional overload choice.
```

Resolves: [SR-8411](https://bugs.swift.org/browse/SR-8411)
2019-11-07 17:00:59 -08:00
Pavel Yaskevich
3d10f33e87 Merge pull request #28131 from xedin/remove-argument-matcher
[CSDiag] Remove obsolete `ArgumentMatcher` from `FailureDiagnosis`
2019-11-07 15:31:40 -08:00
Robert Widmann
41ab235797 [CS] Remove some TypeChecker uses 2019-11-07 12:41:37 -08:00
Pavel Yaskevich
c3acce4d69 [CSDiag] Remove obsolete ArgumentMatcher from FailureDiagnosis
All of the argument diagnostics have been ported to the new diagnostic
framework, so now is the time to remove `ArgumentMatcher` and the only
place where it was used - `diagnoseSingleCandidateFailures`.
2019-11-07 11:17:01 -08:00
Hamish Knight
18088b04f0 [AST] Consolidate Obj-C types on ASTContext
This commit moves the getNSObjectType and
getObjCSelectorType methods from TypeChecker
onto ASTContext. In addition, it moves the
FOR_KNOWN_FOUNDATION_TYPES macro into a separate
file to define each of the Obj-C type decls
we want to have access to.
2019-11-07 08:26:08 -08:00
Holly Borla
b560261838 [ConstraintSystem] Allow binding metatypes to succeed if one contains
a hole.
2019-11-06 14:02:36 -08:00
Pavel Yaskevich
97773baf71 [ConstraintSystem] Allow function mismatch in assignment to be diagnosed 2019-11-05 12:45:31 -08:00
Pavel Yaskevich
4eaf159eab [ConstraintSystem] Impact of r-value as l-value fix is higher for functions/subscripts
If the fix is applied to result type of a function or subscript
invocation increase its impact because such uses are invalid
e.g. assigning a value to a function call `foo() = 42`, or
using read-only subscript as mutating.
2019-11-05 12:43:32 -08:00
Pavel Yaskevich
c800bde8e1 [Diagnostics] Try to find overlap between src/dst protocols in assignment mismatch 2019-11-05 12:43:32 -08:00
Pavel Yaskevich
6670d628ca [Diagnostics] Diagnose an attempt to assign to immutable IUO declaration 2019-11-05 12:43:32 -08:00
Pavel Yaskevich
11644b3f31 [Diagnostics] Diagnose assignment type mismatches related to unresolved members 2019-11-05 12:43:32 -08:00
Pavel Yaskevich
6f919786b8 [ConstraintSystem] Detect and diagnose assignment type mismatches related to existentials 2019-11-05 12:38:13 -08:00
Pavel Yaskevich
3586af6e8a [Diagnostics] Properly diagnose assignment type mismatches when either side is optional 2019-11-05 12:38:13 -08:00
Pavel Yaskevich
a587278162 [ConstraintSystem] Detect and diagnose assignment failures related to opaque result types
An attempt to assign result type of one declaration to opaque result
of another is not supported and should be diagnosed as assignment failure.
2019-11-05 12:38:13 -08:00
Pavel Yaskevich
d23adafd3c [ConstraintSystem] Handle assignment to AnyObject as a contextual type mismatch
Contextual diagnostics already have a special case for `AnyObject`
conversions which is going to be diagnosed as a missing conformance.
2019-11-05 12:38:13 -08:00
Pavel Yaskevich
723e438c78 [ConstraintSystem] Record contextual mismatch if type is missing conformance in assignment
```swift
struct S {}

protocol P {}

func foo(_ value: S) {
  var p: P? = nil
  p = value
}
```

Assignment destination is a protocol `P` and source is a type `S`
which doesn't conform to `P`. Allow solver to detect this situation
and record `ignore assignment destination type` fix which would
cover a single missing conformance as well as protocol composition.
2019-11-05 12:38:13 -08:00
Pavel Yaskevich
cb3a0fbcc8 [ConstraintSystem] Extend use of the treat r-value as l-value fix to more cases
Cover not only immutability but also type mismatch cases and clarify
behavior when one of the sides of the type conversion is optional.
2019-11-05 12:38:13 -08:00
Holly Borla
cc65d2112d [ConstraintSystem] Fix a few places where we should consider
`matchTypes` a success without applying new constraint fixes
due to the presence of holes.
2019-11-05 09:16:57 -08:00
Holly Borla
4fd1377c81 [ConstraintSystem] With the new approach for holes, hole propagation happens
automatically.

This commit also renames `ConstraintSystem::recordHole/isHole` to
`recordPotentialHole` and `isPotentialHole` to make it clear that
we don't know for sure whether a type variable is a hole until it's
bound to unresolved.
2019-11-05 09:15:13 -08:00
Holly Borla
e840d52258 [Diagnostics] Allow fixes with the same locator to be coalesced before
application rather than throwing away subsequent fixes.

The "primary fix" decides whether or not to coalesce fixes that have
the same locator.
2019-11-05 09:15:13 -08:00
Holly Borla
561e527848 [ConstraintSystem] Extend the ExplicitlySpecifyGenericArguments fix to cover
all cases of missing generic parameters.

In `ComponentStep::take` when there are no bindings or disjunctions, use hole
propagation to default remaining free type variables that aren't for generic
parameters and continue solving. Rather than using a defaultable constraint for
holes, assign a fixed type directly when we have no bindings to try.
2019-11-05 09:15:13 -08:00
Suyash Srijan
5ff654d055 Merge pull request #27995 from theblixguy/fix/SR-11684
[PropertyWrappers] Mark the property as invalid when there is a mismatch with wrappedValue type
2019-11-05 01:25:51 +00:00
Suyash Srijan
573aceeba3 [ConstraintSystem] Don't create a AllowArgumentMismatch fix when there is an argument type mismatch in synthesized wrappedValue init
This is because we already emit a diagostic to tell the user that the property's type does not match the wrappedValue type, so this diagnostic can be a bit confusing especially because the initializer is synthesized
2019-11-04 22:29:13 +00:00
Hamish Knight
e7fe2a7a48 Prevent non-ephemeral fix from affecting overload resolution
This commit changes the behaviour of the error for
passing a temporary pointer conversion to an
@_nonEphemeral parameter such that it doesn't
affect overload resolution. This is done by recording
the fix with an impact of zero, meaning that we don't
touch the solution's score.

In addition, this change means we no longer need
to perform the ranking hack where we favour
array-to-pointer, as the disjunction short-circuiting
will continue to happen even with the fix recorded.
2019-11-03 08:42:26 -08:00
Hamish Knight
7077a68b83 [Sema] Diagnose unsound pointer conversions
Diagnose ephemeral conversions that are passed to @_nonEphemeral
parameters. Currently, this defaults to a warning with a frontend flag
to upgrade to an error. Hopefully this will become an error by default
in a future language version.
2019-11-03 08:42:25 -08:00
Pavel Yaskevich
88c477b08d [ConstraintSystem] Accept trailing closure if the last parameter is defaulted
If the last parameter is defaulted, there might be
an attempt to use a trailing closure with previous
parameter that accepts a function type e.g.

```swift
func foo(_: () -> Int, _ x: Int = 0) {}
foo { 42 }
```

Resolves: rdar://problem/55102498
2019-11-01 14:00:11 -07:00
Pavel Yaskevich
495f14a698 [ConstraintSystem] Use new trailing closure fix in matchCallArguments 2019-11-01 01:20:13 -07:00
Pavel Yaskevich
82c2456295 Merge pull request #27976 from xedin/extraneous-call
[Diagnostics] Introduce extraneous call fix
2019-10-31 11:57:03 -07:00
Pavel Yaskevich
1315207a22 [Diagnostics] Introduce extraneous call fix
Detect and diagnose attempts to call variables and/or properties
which don't have a function type, so can't really support
invocation.
2019-10-30 16:53:42 -07:00
Robert Widmann
4996858c4d Re-implement isInvalid for ValueDecls 2019-10-30 15:09:14 -07:00
Robert Widmann
929332e12a Make isAvailabilitySafeForConformance a utility 2019-10-30 12:55:42 -07:00
Robert Widmann
972e755e9b Give ConstraintSystem's outlet to the ASTContext
Make it less tempting to ask for the type checker embedded into
ConstraintSystem by using the accessor to the ASTContext.
2019-10-30 12:55:42 -07:00
Robert Widmann
da2b063af9 Make calls to lookupMember actually look static 2019-10-30 12:55:42 -07:00
Robert Widmann
b849e51768 Use operator bool to claw back some readability 2019-10-29 16:56:21 -07:00
Robert Widmann
3e1a61f425 [NFC] Fold The Tri-State In Optional<ProtocolConformanceRef>
ProtocolConformanceRef already has an invalid state.  Drop all of the
uses of Optional<ProtocolConformanceRef> and just use
ProtocolConformanceRef::forInvalid() to represent it.  Mechanically
translate all of the callers and callsites to use this new
representation.
2019-10-29 16:55:56 -07:00
Pavel Yaskevich
58329e0c27 Revert "[Diagnostics][Qol] SR-11295 Emit diagnostics for same type coercion. " 2019-10-25 01:05:07 -07:00
Luciano Almeida
a92e62f51f Fixing formatting issues 2019-10-23 23:54:48 -03:00
Luciano Almeida
5d1eeacbe4 Resolving conflicts 2019-10-23 07:25:55 -03:00
Pavel Yaskevich
d5b232c26e Merge pull request #27834 from xedin/for-in-diag
[TypeChecker] Produce a tailored diagnostic for `for-in` sequence fai…
2019-10-23 00:32:35 -07:00
Pavel Yaskevich
fb6ce64628 Merge pull request #27842 from xedin/if-ternary-diags
[Diagnostics] Improve if/ternary condition expression diagnostics
2019-10-23 00:32:06 -07:00
Pavel Yaskevich
74a7f3d8d0 [TypeChecker] Produce a tailored diagnostic for for-in sequence failures
`for-in` "sequence" expression is required to conform to `Sequence`.
2019-10-22 16:57:28 -07:00
Pavel Yaskevich
c4fee1d0c9 [ConstraintSystem] Use new condition element in constraint generation/diagnostics 2019-10-22 15:01:49 -07:00
Hamish Knight
be23ecc878 These functions don't need a TypeChecker 2019-10-22 09:23:33 -07:00
Luciano Almeida
cac0d07d78 Attempting UnnecessaryCoercion for ExplicityTypeCoercion on CSSimplify 2019-10-21 23:05:06 -03:00