Commit Graph

483 Commits

Author SHA1 Message Date
Hamish Knight
a97328dcbf [CS] Use a MapVector to cache resolved overloads
Rather than maintaining a linked list of overload
choices, which must be linearly searched each time
we need to lookup an overload at a given callee
locator, use a MapVector which can be rolled back
at the end of a scope.

Remove ResolvedOverloadSetListItem in favor of
using SelectedOverload, which avoids the need to
convert between them when moving from
ConstraintSystem to Solution.
2019-12-05 14:47:52 -08:00
Pavel Yaskevich
3c5290c78c [Diagnostics] Diagnose inability to infer contextual base type for member ref 2019-12-03 12:07:16 -08:00
Pavel Yaskevich
34f5b52db1 [Diagnostics] Diagnose ambiguities related to contextual type mismatch
If none of the candidates produce expected contextual type, record
all of the posibilities to produce a note per and diagnose this as
contextual type mismatch instead of a reference ambiguity.
2019-12-03 12:07:15 -08:00
Pavel Yaskevich
a9f11445c0 [Diagnostics] Diagnose an attempt to assign a value to an overloaded name
Example:

```swift
struct X {
}

func X(_: Int) -> Int {
  return 42
}

X = 42
```
2019-12-03 12:07:15 -08:00
Slava Pestov
2e65a14ed4 Merge pull request #28372 from slavapestov/typecheck-decl-primary
Kill ClosuresWithUncomputedCaptures and split off TypeCheckDeclPrimary.cpp from TypeCheckDecl.cpp
2019-11-20 14:29:31 -05:00
Pavel Yaskevich
38a6cfaad1 [CSDiagnostic] Convert force optional unwrap diagnostic into a contextual one
Record both sides of conversion where a form of force unwrap is
necessary to be able to produce tailored diagnostics such as for
an attempt to use optional type as a boolean.
2019-11-19 15:15:29 -08:00
Slava Pestov
ef05accd31 Sema: Remove even more vestigial TypeChecker usages 2019-11-19 17:40:00 -05:00
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
Doug Gregor
bc926f7eb7 [Constraint system] Drop the root expression from FailureDiagnostic.
We're not using it for anything, now.
2019-11-08 22:38:49 -08:00
Doug Gregor
c744066c52 [Constraint solver] Stop using the "root expression" in failure diagnostics.
We're still using the root expression to find the parent map, but we're not
falling back to it indiscriminately. Use the parent of the anchor (or
appropriate substitute) instead so we have a better handle on which
expression we're diagnosing for.
2019-11-08 21:26:04 -08:00
Pavel Yaskevich
6d02fb7815 Merge pull request #28057 from xedin/assign-diags
[Diagnostics] Port the rest of assignment diagnostics to the new framework
2019-11-06 00:11:08 -08:00
Robert Widmann
53f2974e27 [NFC] Remove unnecessary TypeCheckers from sequence folding 2019-11-05 20:30:40 -08:00
Hamish Knight
912a7acc1e Add FunctionArgApplyInfo::getArgDescription
This commit adds a member which produces a string
describing the argument being applied. This will
either be its argument label or position in the
argument list.
2019-11-05 13:51:53 -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
30440d8235 [Diagnostics] Properly diagnose assignment mismatch in ambiguity cases 2019-11-05 12:38:13 -08:00
Holly Borla
33b9d4c446 [Diagnostics] Change FailureDiagnostic::resolveType to replace
holes with generic parameters directly when possible.
2019-11-05 09:17:53 -08:00
Holly Borla
e63f259f4f [ConstraintSystem] Bind holes to UnresolvedType instead of Any. 2019-11-05 09:15:13 -08:00
Hamish Knight
d0dbbf9f89 [CSDiagnostics] Add ephemeralness ambiguity notes 2019-11-03 08:42:25 -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
6bb659c5a3 [Diagnostics] Add a diagnostic for incorrect use of trailing closures 2019-10-31 20:58:01 -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
Pavel Yaskevich
58329e0c27 Revert "[Diagnostics][Qol] SR-11295 Emit diagnostics for same type coercion. " 2019-10-25 01:05:07 -07:00
Luciano Almeida
3dc82a6271 Handling ExplicityCoercion in simplifyLocator 2019-10-24 00:27:53 -03:00
Luciano Almeida
5d1eeacbe4 Resolving conflicts 2019-10-23 07:25:55 -03:00
Luciano Almeida
4385dd854f Creating UnnecessaryCoercion warning fix 2019-10-21 23:03:12 -03:00
Anthony Latsis
d64d45d3d6 @lvalue exposure fixes & prevention 2019-10-22 04:30:40 +03: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
0d95a84e91 [Diagnostics] Improve the error message for when a type fails to satisfy
`AnyObject` layout requirement.
2019-10-18 11:27:21 -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
Holly Borla
ef0ecc41e5 [ConstraintSystem] Diagnose missing AnyObject conformance using
the MissingConformance constraint fix.
2019-10-16 20:38:00 -07:00
Pavel Yaskevich
9913f8db27 [Diagnostics] NFC: Use isLastElement API instead of checking locator path 2019-10-16 10:19:26 -07:00
Pavel Yaskevich
c97603f5d4 [CSDiagnostics] Diagnose extraneous arguments 2019-10-16 10:19:25 -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
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
Luciano Almeida
12f98d7922 Merge branch 'master' into force-downcast-fix-explicit-coercion 2019-10-06 13:35:44 -03:00
Hamish Knight
6e3671da41 Move FunctionArgApplyInfo up the header 2019-10-03 16:53:37 -07:00
Hamish Knight
b5a0d58dc0 Have ArgumentMismatchFailure store FunctionArgApplyInfo
And define members in order to allow the easy
access of relevant information about the failure.
2019-10-03 15:26:31 -07:00
Hamish Knight
12c1db9c93 NFC: Move ArgumentMismatchFailure down a bit
Just to make sure it's defined after
FunctionArgApplyInfo.
2019-10-03 15:08: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
980ff05972 Add ForceDownCast fix for coercion expr to avoid fall-through into CSDiag 2019-10-01 20:25:15 -03:00
Robert Widmann
5a8d0744c3 [NFC] Adopt TypeBase-isms for GenericSignature
Structurally prevent a number of common anti-patterns involving generic
signatures by separating the interface into GenericSignature and the
implementation into GenericSignatureBase.  In particular, this allows
the comparison operators to be deleted which forces callers to
canonicalize the signature or ask to compare pointers explicitly.
2019-09-30 14:04:36 -07:00
Pavel Yaskevich
10b1baebb2 Merge pull request #27362 from xedin/port-missing-args
[Diagnostics] Port missing argument(s) diagnostics
2019-09-25 21:08:54 -07:00
Pavel Yaskevich
cc2c868522 [Diagnostics] Produce a tailored diagnostic for multiple missing arguments 2019-09-24 22:05:14 -07:00
Robert Widmann
62266447f2 Drop the TypeChecker dependency from some helpers 2019-09-24 17:48:42 -07:00
Pavel Yaskevich
2120a31cf0 [Diagnostics] Correctly diagnose misplaced missing argument
Due to the fact that `matchCallArgument` can't and
doesn't take types into consideration while matching
arguments to parameters, when both arguments are
un-labeled, it's impossible to say which one is missing:

func foo(_: Int, _: String) {}
foo("")

In this case first argument is missing, but we end up with
two fixes - argument mismatch (for #1) and missing argument
(for #2), which is incorrect so it has to be handled specially.
2019-09-24 10:24:21 -07:00