Commit Graph

535 Commits

Author SHA1 Message Date
Amritpan Kaur
cb984791d6 [NFC] Move keypath diagnostic from general to keypath 2023-08-01 12:11:51 -07:00
Amritpan Kaur
59d26795c2 [Test] Add AnyKeyPath test and move keypath diagnostics 2023-08-01 12:11:27 -07:00
Crazy凡
4e346c1cf8 Add test cases for the 'nil coalescing operator'. 2023-07-04 18:21:26 +08:00
Slava Pestov
1957bd6065 Sema: Reword diagnostics to say 'without a type annotation' instead of 'without more context' 2023-06-09 17:44:42 -04:00
Pavel Yaskevich
5f8e3eb6f6 [CSSimplify] Detect and diagnose conformance failures related to AnyHashable conversion
Failure of an argument to AnyHashable parameter to conform to Hashable
protocol should be detected in `simplifyConformsToConstraint` and fixed
there.

Doing so requires impact assessment adjustment because regular conformance
requirements have default impact of 1, this is going to have argument
impact of 2 not avoid clashing with other failures.
2023-05-08 16:16:30 -07:00
Anthony Latsis
14b70f306b DiagnosticVerifier: Default expected fix-it start line to the diagnostic's 2023-03-08 12:10:27 +03:00
Luciano Almeida
22a18de1b1 [Sema] Improving integer literal as boolean diagnostic 2023-02-21 10:30:48 -03:00
Hamish Knight
f7191b35b6 [CS] Add contextual Bool type to switch-case where clause
Seems this was accidentally omitted, which would
crash in CSApply for any non-Bool-convertible type.
2023-02-17 20:58:46 +00:00
Cal Stephens
c2bf0f943e Revert "Combine the two diagnostics"
This reverts commit 2e7656218e.
2022-09-01 08:11:46 -07:00
Cal Stephens
2e7656218e Combine the two diagnostics 2022-09-01 06:23:42 -07:00
Cal Stephens
88b65f406f Update tests 2022-08-31 20:14:41 -07:00
Anthony Latsis
e51ef47b37 Gardening: Migrate test suite to GH issues: Constraints (5/5) 2022-08-19 06:35:23 +03:00
Hamish Knight
1bf954c61f [CS] Better diagnose inout argument in tuple construction
Previously we relied on `TupleTypeElt::getType`
returning an `InOutType` to fail the tuple type
matching logic. Instead, add logic to reject any
inout arguments up-front with a more specific
diagnostic.

Also, while we're here, strip the `_const`
parameter flag, as it's not something that needs
to be considered for tuple construction.
2022-08-02 13:56:30 +01:00
Hamish Knight
4915513387 [CS] Filter out uncallable vars when simplifying applied overloads
This improves diagnostics as we can now consider
functions that don't line up exactly with the
argument list if no other viable candidates exist.
2022-07-26 12:51:53 +01:00
Alex Hoppen
e14fa7291f [CS] Don’t fail constraint generation for ErrorExpr or if type fails to resolve
Instead of failing constraint generation by returning `nullptr` for an `ErrorExpr` or returning a null type when a type fails to be resolved, return a fresh type variable. This allows the constraint solver to continue further and produce more meaningful diagnostics.

Most importantly, it allows us to produce a solution where previously constraint generation for a syntactic element had failed, which is required to type check multi-statement closures in result builders inside the constraint system.
2022-07-20 09:46:12 +02:00
Pavel Yaskevich
a0d132582e [Diagnostics] Improve diagnostic message for extraneous &
Resolves: https://github.com/apple/swift/issues/58389
2022-04-25 15:08:04 -07:00
Pavel Yaskevich
5331e276d5 Merge pull request #41730 from xedin/se-0326-solve-pattern-bindings-via-conjunctions
[SE-0326] Re-enable multi-statement closure inference by default
2022-03-15 13:21:03 -07:00
Pavel Yaskevich
966f58f044 [Tests] NFC: Adjust all the test-cases improved by multi-statement inference 2022-03-08 01:13:44 -08:00
Holly Borla
12459cff80 [Diagnostics] Print 'any' in diagnostic arguments. 2022-03-05 14:26:45 -08:00
Robert Widmann
74bb62b562 Ban Placeholders in More Places
Fix a regression introduced in #39627 where placeholders at the "top level" were mistaken for "placeholders in top level code".
2022-02-02 12:39:56 -08:00
Pavel Yaskevich
d5b11a6136 [CSFix] Make it possible to diagnose calls to non-functions in ambiguity contexts
Resolves: rdar://86611718
2021-12-20 18:12:45 -08:00
Pavel Yaskevich
bc54bc6bb7 Revert "[TypeChecker] SE-0326: Enable multi-statement closure inference by default" 2021-11-29 17:26:08 -08:00
Xi Ge
1ea431645b test: update Constraints/diagnostics.swift 2021-11-23 19:54:25 -08:00
Pavel Yaskevich
67d87e104f [Tests] NFC: Adjust all the test-cases improved by multi-statement inference 2021-11-15 16:42:06 -08:00
Robert Widmann
22ad19f64b Revert "[Sema] Diagnose and reject top-level placeholders"
This reverts commit f6b6bff6de.
2021-11-03 10:29:14 -07:00
Karoy Lorentey
e2cfab4f28 [stdlib][test] Adopt availability macros in tests 2021-10-31 15:00:58 -07:00
Frederick Kellison-Linn
f6b6bff6de [Sema] Diagnose and reject top-level placeholders 2021-08-19 14:53:34 -04:00
Frederick Kellison-Linn
16a4031c32 [tests] Update tests with modified diagnostics 2021-08-19 14:53:34 -04:00
Hamish Knight
21e8a320ec [CS] Better handle paren fix-its for unresolved chains
I missed this case when previously improving the
logic here. As it turns out, using the raw anchor
as the root expression from which to derive parent
information is insufficient. This is because it
may not capture relevant parent exprs not a part
of the fix locator.

Instead, pass down a function that can be used to
derive the parent expressions from the constraint
system's own parent map. Also make sure to assign
to `expr` for the UnresolvedMemberChainResultExpr
case to make sure we correctly check for it as a
sub-expression.

Finally, now that we're looking at more parent
exprs, add logic to handle `try` and `await`
parents, as well as ClosureExprs and
CollectionExprs. I couldn't come up with a test
case for CollectionExpr, as we emit different
diagnostics in that case, but it's probably better
to tend on the side of being more future proof
there.

rdar://81512079
2021-08-04 14:34:24 +01:00
Hamish Knight
5d1fea24ad [CS] Don't consider implicit TupleExprs in exprNeedsParensOutsideFollowingOperator
Such implicit tuples may be used to represent
argument lists for e.g binary expressions, and as
such shouldn't be considered as parent exprs that
satisfy the role of parentheses.

Also fix the callers to use the raw anchor as the
root expression they pass to provide an accurate
parent map. This requires sinking the
UnresolvedMemberChainResultExpr handling logic into
`getPrecedenceParentAndIndex`.

rdar://81109287
2021-07-26 18:17:01 +01:00
Doug Gregor
1e2012d816 Disable availability checking in tests that use concurrency 2021-07-20 12:46:26 -07:00
jiaren wang
c5de1f0800 [SR-14824] Improve diagnostic for multi-statement closures instead of saying "too complex closure return type" 2021-06-30 14:36:38 +08:00
Holly Borla
89418c6766 Merge pull request #38112 from hborla/return-type-fixit-loc
[Diagnostics] Correct the insert location of missing return type fix-it.
2021-06-28 16:29:34 -07:00
Pavel Yaskevich
6fcb47d790 Merge pull request #38111 from xedin/rdar-79672230
[Diagnostics] Fix requirement note to properly handle layout requirements
2021-06-28 10:03:08 -07:00
Holly Borla
e139c45702 [Diagnostics] In ExtraneousReturnFailure, insert the return type fix-it
after any effects specifiers like async, throws, rethrows, etc.
2021-06-28 09:44:38 -07:00
Pavel Yaskevich
b4976df82c [Diagnostics] Adjust missing conformance note to use ':' instead of '==' 2021-06-25 12:05:47 -07:00
Holly Borla
db3066ddcc [NFC][Diagnostics] Add a test case for rdar://71829040. 2021-06-24 10:03:09 -07:00
Holly Borla
d083c66686 [ConstraintSystem] Before matching tuple types, add each complete tuple
type to the locator.

This will provide context for tuple element mismatch diagnostics, instead
of attempting to compute the full tuple type in diagnostics code with a pile
of special cases (see getStructuralTypeContext in CSFix.cpp).
2021-06-24 09:40:14 -07:00
Pavel Yaskevich
2b207e8f07 [Diagnostics] Augment "expected parameter" note with an argument type
Currently ambiguity notes attached to a candidate only mention
expected type and its position. To improve clarify of such notes
it's useful to print argument type as well since it's not always
clear what it is at the first glance at the code.

Resolves: SR-14634
Resolves: rdar://78224323
2021-05-26 12:58:35 -07:00
Holly Borla
c297070106 [Diagnostics] Always use the parameter name for closure parameter diagnostics,
because the $ prefix does not indicate that the parameter is anonymous.
2021-05-11 18:30:27 -07:00
Pavel Yaskevich
f36ecf2fa1 [CSSimplify] Allow overload choices with missing labels to be considered for diagnostics
Let's make use of a newly added "disable for performance" flag to
allow solver to consider overload choices where the only issue is
missing one or more labels - this makes it for a much better
diagnostic experience without any performance impact for valid code.
2021-04-28 12:04:57 -07:00
Pavel Yaskevich
dd70528e6b [Diagnostics] Verify that optional evaluation got type from context before recording a fix
Instead of assuming that there is a mismatch between context and
result of the optional chain, let's actually verify that optional
evaluation expression does have a type before recording a fix.

Resolves: rdar://74696023
2021-03-08 11:48:04 -08:00
Robert Widmann
13ff5bb569 Fixup Diagnostic Expectations 2021-03-06 09:26:23 -08:00
Pavel Yaskevich
cb36fb723c [TypeChecker] NFC: Adjust tests impacted by binding ordering change 2021-02-24 10:38:31 -08:00
Pavel Yaskevich
f24e5dbd26 [Diangostics] NFC: Adjust test-cases to expect that "type cannot conform" diagnostic has a note 2020-10-27 14:54:07 -07:00
Pavel Yaskevich
f97e80347b [Diagnostics] Allow "unknown base" fix to be diagnosed in ambiguity situations
If there are multiple overloads and all of them require explicit
base type for a member reference, let's diagnose it as a single
error since the problem is the same across the overload choices:

```swift
func foo<T>(_: T, defaultT: T? = nil) {}
func foo<U>(_: U, defaultU: U? = nil) {}

foo(.bar)
```

In this example there is not enough contextual information to
determine base type of `.bar` reference and hence both `foo`
overloads are a considered valid solutions until explicitly set
base type disambiguates them.

Resolves: rdar://problem/66891544
2020-09-21 15:53:11 -07:00
Frederick Kellison-Linn
5b5e30b6d7 Implement implicit member chains 2020-08-26 22:42:29 -04:00
Doug Gregor
25d40125e9 [Trailing closures] Bias toward the backward scan for ambiguities.
This approach, suggested by Xiaodi Wu, provides better source
compatibility for existing Swift code, by breaking ties in favor of the
existing Swift semantics. Each time the backward-scan rule is needed
(and differs from the forward-scan result), we will produce a warning
+ Fix-It to prepare for Swift 6 where the backward rule can be
removed.
2020-07-24 08:47:51 -07:00
Doug Gregor
4acb094677 Fix a NULL pointer dereference and update test cases. 2020-07-24 08:11:25 -07:00
Luciano Almeida
8e8f081b3e [Sema] Inncrease the score a bit higher for argument mismatch and updating tests 2020-07-23 21:35:52 -03:00