Commit Graph

1225 Commits

Author SHA1 Message Date
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
Robert Widmann
a537e04a12 Break Another Overload Resolution Cycle
Resolve a cycle caused by overload resolution considering recursive
static candidates where before it would silently reject them.  In
a world before the InterfaceTypeRequest, the overload resolution
machinery would attempt to validate the declaration and would recieve
a bad answer.  This caused circular candidates to be ignored as a side
effect.  This behavior was partially restored by the fixes in #27725 and #27668
but that isn't enough for recursive static variables.  Even if it were,
the constraint fix kind doesn't make sense.

Luckily, the right answer is to just reject recursive static VarDecl
candidates entirely.

Addresses rdar://56410015
2019-10-20 23:56:00 -07:00
Holly Borla
e5c99cace6 Merge pull request #27769 from hborla/anyobject-conformance-failure
[ConstraintSystem] Diagnose missing AnyObject conformance using the MissingConformance constraint fix.
2019-10-18 22:10:21 -04:00
Holly Borla
dca1373e46 [ConstraintSystem] Don't fail in matchTypes when two primary archetype types
are not equal when part of a type requirement. This allows the
SkipSameTypeRequirement constraint fix to be applied instead.
2019-10-18 17:34:03 -07:00
Pavel Yaskevich
8d05192204 Merge pull request #27728 from xedin/port-extraneous-args
[Diagnostics] Diagnose extraneous argument(s) via fixes
2019-10-18 10:42:56 -07:00
Holly Borla
ec864fcd9c [ConstraintFix] Don't pass along the RequirementKind to the MissingConformance
constraint fix. Instead, get the kind from the locator.
2019-10-18 09:03:06 -07:00
Pavel Yaskevich
14d9011c2b Merge pull request #27759 from xedin/port-keypath-diags
[Diagnostics] Port more key path related failures to new framework
2019-10-18 01:02:43 -07:00
Holly Borla
f998349815 [Diagnostics] Add a tailored note for when the Wrapped type of an
optional satisfies a failed requirement.
2019-10-17 19:59:07 -07:00
Pavel Yaskevich
0d07cd87ac [ConstraintSystem] Detect and diagnose contextual mismatches in key path components 2019-10-17 13:52:00 -07:00
Pavel Yaskevich
57c770238c [ConstraintSystem] Detect and diagnose missing member refs in key path
Key path components can reference an invalid or missing member
just like regular expressions, so we need to account for that
while trying to simplify key path constraint.
2019-10-17 12:55:08 -07:00
Pavel Yaskevich
d379e2387e Merge pull request #27473 from LucianoPAlmeida/force-downcast-fix-explicit-coercion
[ConstraintSystem] Diagnosing invalid explicit coercion via fix
2019-10-17 00:41:01 -07:00
Holly Borla
ef0ecc41e5 [ConstraintSystem] Diagnose missing AnyObject conformance using
the MissingConformance constraint fix.
2019-10-16 20:38:00 -07:00
Pavel Yaskevich
09a36ddf17 [ConstraintSystem] Adjust keypath subscript assert to account for dynamic member lookup
It's possible to find a suitable overload choice for
key path application through keypath dynamic member
lookup and assertion inside `addKeyPathApplicationRootConstraint`
should account for that.

Resolves: rdar://problem/56350060
2019-10-16 16:38:16 -07:00
Pavel Yaskevich
2a0080c6e0 [Diagnostics] Add a workaround for inability to diagnose name shadowing
Let's cover at least the most common cases - min/max. Fixing the
problem requires refactoring of `resolveDeclRefExpr`.
2019-10-16 10:19:26 -07:00
Pavel Yaskevich
8d3409bddf [ConstraintSystem] Allow argument matcher to continue in presence of missing/extra arguments
This makes it possible to find all of the problems related to a given
set of arguments and fix/score each overload candidate correctly.
2019-10-16 10:19:26 -07:00
Pavel Yaskevich
1022ac7678 [ConstraintSystem] Check whether extraneous arguments are related to tuple splat
Before recording a generic "extraneous arguments" fix, let's check
whether this is a tuple splat with a single parameter.
2019-10-16 10:19:26 -07:00
Pavel Yaskevich
1b7dc3209b [ConstraintSystem] Fix an attempt to construct Void type with arguments 2019-10-16 10:19:26 -07:00
Pavel Yaskevich
1b302b98d3 [ConstraintSystem] Record a fix for extraneous arguments after matcher is done 2019-10-16 10:19:26 -07:00
Pavel Yaskevich
e97164dfce [CSFix] Record all available information about extraneous arguments
Most importantly - index, label, and type, which are useful for
diagnostics.
2019-10-16 10:19:25 -07:00
Pavel Yaskevich
e33a3402cb [ConstraintSystem] Make contextual function type available for matchCallArguments
Helps diagnostics to avoid digging this type out from locator.
2019-10-16 10:19:25 -07:00
Pavel Yaskevich
86bcecf5fc [CSSimplify] Introduce extraneous argument fixes 2019-10-16 10:19:25 -07:00
Pavel Yaskevich
22813d96cf [ConstraintSystem] Extend MatchCallArgumentListener::extraArguments to return all extraneous arguments 2019-10-16 10:19:25 -07:00
Pavel Yaskevich
f1ed46ee82 [CSFix] Add a fix to remove extraneous arguments
If there are more arguments than parameters, let's fix this by
ignoring (if possible) or removing extraneous arguments. Ignored
arguments could default to `Any` if they don't get any other
contextual type.
2019-10-16 10:19:25 -07:00
Luciano Almeida
73dcc4b5e8 Merge branch 'master' of https://github.com/apple/swift into force-downcast-fix-explicit-coercion 2019-10-15 19:18:46 -03:00