Commit Graph

1199 Commits

Author SHA1 Message Date
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
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
Hamish Knight
fc020bb3f4 [CS] Add ConstraintSystem::addFixConstraint
This lets us add a constraint to the system with an associated fix.
Unlike `addUnsolvedConstraint`, this will attempt to immediately
simplify the constraint, producing an unsolved constraint if necessary.
2019-10-15 10:12:48 -07:00
Hamish Knight
9d21fbb445 [CS] Don't try inout-to-ptr for array to raw ptr
Array-to-pointer should only be used for such conversions. This isn't
currently an issue as we short-circuit disjunctions upon successfully
solving an array-to-pointer conversion. However this would become an
issue if only inout-to-pointer was viable.
2019-10-15 10:12:48 -07:00
Hamish Knight
2759ae29bb [AST] Add TypeBase::lookThroughSingleOptionalType 2019-10-15 10:12:48 -07:00
Robert Widmann
f15544de0b Strike VarDecls in Pattern Binding Initializers From Overloads
We would previously consider the VarDecls bound by a particular pattern
binding initializer context when performing overload resolution.  This
would lead to circular validation.  Validation was tacitly breaking the
cycle by returning an error type (but, crucially, not setting that
interface type).  Instead, pre-reject circular candidates.

This greatly improves the diagnostic we emit here in truly circular
cases since we can ride on `UR_InstanceMemberOnType` to yield

struct PatternBindingWithTwoVars2 { var x = y, y = 3 }
// cannot use instance member 'y' within property initializer; property initializers run before 'self' is available
2019-10-14 11:54:24 -07:00
Luciano Almeida
30ffe13cba Merge branch 'master' of https://github.com/apple/swift into force-downcast-fix-explicit-coercion 2019-10-13 11:09:37 -03:00
Luciano Almeida
d896968d2c clang-format 2019-10-12 22:39:12 -03:00
Luciano Almeida
697b407589 Fixing test on test/Generics/conditional_conformances.swift 2019-10-12 18:20:23 -03:00
Luciano Almeida
05cea3a7b7 Fix issue with dictionary_downcast tests 2019-10-12 16:49:36 -03:00
Luciano Almeida
f39ff88113 Initial implementation of moving the checks 2019-10-12 15:22:16 -03:00
Luciano Almeida
21c179d46f Removing fixed CoerceToCheckedCast constraint and letting repairFailures handle the diagnostics 2019-10-12 11:38:59 -03:00
swift-ci
7d437ec4a8 Merge pull request #27629 from DougGregor/builder-refactoring-prelude 2019-10-11 15:35:11 -07:00
Pavel Yaskevich
6b9b764974 Merge pull request #27614 from xedin/inout-type-mismatch
[ConstraintSystem] Detect and diagnose type mismatch failures of `ino…
2019-10-11 14:14:09 -07:00
Doug Gregor
eb61ae7971 [Type checker] Factor out ConstraintSystem::addJoinConstraint().
Use it for ternary expressions; it'll gain other clients soon.
2019-10-11 10:07:21 -07:00
Pavel Yaskevich
1846a5957e Merge pull request #27608 from xedin/autoclosure-ctx-mismatch
[Diagnostics] Extend use of argument mismatch fix to `autoclosure` pa…
2019-10-11 02:10:27 -07:00
Pavel Yaskevich
773ac24bc9 [ConstraintSystem] Detect and diagnose type mismatch failures of inout parameters
Currently absence of `subtyping` is the only problem detected and diagnosed specifically
for `inout` parameters, but there could be type mismatches in `inout` positions as well
 and we can use `argument-to-parameter mismatch fix to detect and diagnose them.
2019-10-10 17:06:13 -07:00
Pavel Yaskevich
f09b07be6c [Diagnostics] Extend use of argument mismatch fix to autoclosure parameters
When it comes to `@autoclosure` parameters we only detect and diagnose
mismatches related to invalid implicit conversions to pointer types. But
`@autoclosure` parameters just like regular ones can have type mismatches
as well which can be handled via recently introduced
`argument-to-parameter mismatch` fix.
2019-10-10 13:33:23 -07:00
Brent Royal-Gordon
987b2c96bb Merge pull request #27593 from brentdax/dissolved-in-a-solution
Fix SE-0249 source compatibility break
2019-10-09 21:43:07 -07:00
Brent Royal-Gordon
932128eab6 Fix SE-0249 source compatibility break
In some situations where both the KeyPath and closure solutions for an expression with a keypath literal were valid, the type checker could not choose between them and Swift would emit an “ambiguous use” error. This change increase the typechecking score of the closure solution so that the typechecker will favor the KeyPath solution, preserving source compatibility for existing APIs.

Fixes rdar://problem/56131416.
2019-10-09 17:17:41 -07:00
Luciano Almeida
12f98d7922 Merge branch 'master' into force-downcast-fix-explicit-coercion 2019-10-06 13:35:44 -03:00
Hamish Knight
ec45b24b63 Use hasAppliedSelf in getFunctionArgApplyInfo
`callee->hasCurriedSelf()` isn't the correct check
here when we have an argument mismatch for the
self parameter in a curried application.
2019-10-03 15:26:31 -07:00
Hamish Knight
c108dae5d9 [CSDiagnostics] Find argument lists for key path subscripts
This commit changes `getArgumentExprFor` to take
a ConstraintLocator argument from which to find
the argument list. This lets us properly handle
the case where we have a key path subscript
locator. In addition, this commit renames the
member to `getArgumentListExprFor` to make it
clear we're returning the argument list expression
rather than a single argument.

Resolves SR-11562.
2019-10-02 08:00:14 -07:00
Luciano Almeida
c01688f93f Fixing nit formatting 2019-10-02 07:30:17 -03:00
Luciano Almeida
980ff05972 Add ForceDownCast fix for coercion expr to avoid fall-through into CSDiag 2019-10-01 20:25:15 -03:00
Hamish Knight
6d8b798789 [CS] Have isLastElement take a locator path elt class
This makes it consistent with `getLastElementAs`
and `castLastElementTo`.
2019-09-29 14:19:56 -07:00
Pavel Yaskevich
6aadbc3d52 Merge pull request #27390 from xedin/sr-11491
[Diagnostics] Centralize requirement failure impact assessment
2019-09-27 19:39:36 -07:00
Pavel Yaskevich
24a5003078 [ConstraintSystem] Materialize locator only once per missing argument
Instead of materializing locator twice from the same builder per
missing argument, do it only once and use result to create argument
type variable and its "defaults to Any" constraint.
2019-09-26 20:48:49 -07:00