Commit Graph

95 Commits

Author SHA1 Message Date
Holly Borla
9ba481ad53 [Diagnostics] Clarify the wording of error_in_future_swift_version. 2024-03-01 12:05:51 -08:00
Ben Barham
8bb1ac950b [Parse] Update error if closure has unnamed parameter to warning
This reverts commit 4ba4da45b9 and updates
the warning to a warning until Swift 6.
2024-01-19 12:42:27 -08:00
Doug Gregor
f316c5fcfe Update tests for map switching to typed throws 2024-01-12 10:17:59 -08:00
Alex Hoppen
4ba4da45b9 [Parse] Error if closure has an unnamed parameter
We accepted unnamed closure parameters if the type was an array literal, dictionary literal, tuple or function (because the `[` or `(` starting the type was sufficient to disambiguate the type from the parameter’s name). This was never an accepted syntax and we should disallow it.
2023-11-28 11:07:57 -08:00
Doug Gregor
3baf6ac31a Revert "[Typed throws] Support overrides that are contravariant in the thrown error" 2023-11-16 10:40:23 -08:00
Doug Gregor
b93e228f9d Update tests for map switching to typed throws 2023-11-13 14:13:44 -08:00
Pavel Yaskevich
b07dafab0f [CSSimplify] Exploaded tuple argument should assume param's label if first element doesn't have one
If tuple doesn't have a label for its first element
and parameter does, let's assume parameter's label
to aid argument matching. For example:

```swift
func test(val: Int, _: String) {}

test(val: (42, "")) // expands into `(val: 42, "")`
```

Resolves: rdar://106775969
2023-03-29 10:49:05 -07:00
Anthony Latsis
14b70f306b DiagnosticVerifier: Default expected fix-it start line to the diagnostic's 2023-03-08 12:10:27 +03:00
Anthony Latsis
06be02636c Gardening: Migrate test suite to GH issues: Constraints (3/5) 2022-08-18 05:36:07 +03:00
Rintaro Ishizaki
eade9b7bc9 [LookupVisibleDecls] Implement shadowing for unqualified lookups
Tweaked usable check:
  * Local type/func decls are usable even before declaration
  * Outer nominal Instance member are not usable
  * Type context cannot close over values in outer type contexts

Added shadowing rule by the base name:
  * Type members don't shadow each other as long as they are in the
    same type context.
  * Local values shadow everything in outer scope
    * Except that 'func' decl doesn't shadow 'var' decl if they are in the
      same scope.

rdar://86285396
2022-04-28 16:36:54 -07:00
Josh Soref
8b89b4c995 Spelling constraints (#42548)
* spelling: availability

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: conditional

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: deferred

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: disambiguate

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: failed

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: interferes

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: magnify

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: occurrences

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: overload

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: redeclarations

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: simplification

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: string

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: the

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

Co-authored-by: Josh Soref <jsoref@users.noreply.github.com>
2022-04-22 09:43:26 -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
Pavel Yaskevich
bc54bc6bb7 Revert "[TypeChecker] SE-0326: Enable multi-statement closure inference by default" 2021-11-29 17:26:08 -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
Hamish Knight
4a1a2cdd23 [test] Add tuple splat with vargs test case 2021-09-17 10:52:45 +01:00
Luciano Almeida
3d784687e4 [Sema] Adding a space in closure parameter destructuring fix in cases closure body is empty to avoid invalid inlet code 2021-04-13 23:46:54 -03:00
Pavel Yaskevich
84857b6374 [PreCheck] Remove closure parameter validation
This is no longer necessary since parameter type would be validated
during constraint generation.
2021-03-25 14:34:24 -07:00
Pavel Yaskevich
82fcee7bc7 [Diagnostics] NFC: Adjust diagnostic test-cases improved by new ambiguity diagnosis 2020-06-12 13:13:27 -07:00
Varun Gandhi
a1716fe2a6 [Diagnostics] Update compiler diagnostics to use less jargon. (#31315)
Fixes rdar://problem/62375243.
2020-04-28 14:11:39 -07:00
Pavel Yaskevich
79b757d3cd [ConstraintSystem] Detect and diagnose mismatches in single parameter function conversions
When there is a conversion from e.g. `(A) -> Void` to `(B) -> Void`
matching between `A` and `B` is going to have a special locator which
doesn't end in `TupleElement`, so `repairFailures` has to account
for that and fix it just like regular argument mismatch.

Resolves: rdar://problem/59066040
2020-02-17 16:09:11 -08:00
Pavel Yaskevich
0a8de8bda8 [ConstraintSystem] Allow simplifyRestrictedConstraintImpl to diagnose contextual failures with optionals
Since `simplifyRestrictedConstraintImpl` has both parent types and
does nested type matching it's a good place to diagnose top-level
contextual problems like mismatches in underlying types of optionals.
2020-02-17 16:09:11 -08:00
Pavel Yaskevich
c5ae6c96a9 [ConstraintSystem] Detect missing/extraneous arguments even if there is optional injection required
If parameter type is optional let's ignore that since argument could
be either optional itself or be injected into optional implicitly.

```swift
func foo(_: ((Int, Int) -> Void)!) {}

foo { _ in } // Missing second closure parameter
```
2020-02-05 12:11:01 -08:00
Suyash Srijan
543d649278 [Diagnostics] Warn when the result of a Void-returning function is ignored (by assigning into '_') (#29576) 2020-02-04 20:19:37 +00:00
Pavel Yaskevich
2d10a8a9a0 [ConstraintSystem] Extend function type conversion mismatch coverage
Originally type mismatches associated with conversions between
function types were only covered for coercions and assignments
but fix coverage grew since then and now it makes sense
to remove special case and let `repairFailures` take care of it.
2020-01-30 09:45:36 -08:00
Pavel Yaskevich
09e45823e2 [Diagnostics] NFC: Adjust test-cases improved by changes to closure expression handling 2020-01-14 00:09:33 -08:00
Slava Pestov
1df3d1a33c Frontend: Don't interleave parsing and typechecking for the main file
SIL files still require this behavior; if we cleaned that up we
could simplify a fair bit of code here.

Fixes <https://bugs.swift.org/browse/SR-284>,
<https://bugs.swift.org/browse/SR-4426>.
2019-12-05 08:45:55 -05:00
Pavel Yaskevich
adf83fe9d5 [ConstraintSystem] Fix single tuple vs. N arguments in function conversions 2019-12-03 12:07:15 -08:00
Holly Borla
a9a0bba31b [Diagnostics] Don't apply the single parameter tuple splat fix if the
parameter type is a generic parameter.
2019-11-18 16:19:33 -08:00
Robert Widmann
dd1b15775d Partially Revert #27862
When SE-110 was being implemented, we accidentally began to accept
closure parameter declarations that had no associated parameter names,
e.g.

foo { ([Int]) in /**/ }

This syntax has never been sanctioned by any version of Swift and should
be banned.  However, the change was made long enough ago and there are
enough clients relying on this, that we cannot accept the source break
at the moment.  For now, add a bit to ParamDecl that marks a parameter
as destructured, and back out setting the invalid bit on the type repr
for these kinds of declarations.

To prevent further spread of this syntax, stub in a warning that offers
to insert an anonymous parameter.

Resolves part of rdar://56673657 and improves QoI for errors like
rdar://56911630
2019-11-10 22:10:53 -08:00
Robert Widmann
6dc3f4aad9 Fixup the destructuring diagnostics
Use the isInvalid() bit on the TypeRepr to signal that a closure
parameter is potentially a tuple destructure.  This has two benefits
1) Parse is no longer using the isInvalid() bit on Decl
2) Invalidating the type repr itself means that we no longer spuriously
diagnose variable patterns in destructures as missing types.
2019-10-24 16:03:41 -07:00
Pavel Yaskevich
e09e8c3d72 [Diagnostics] NFC: Adjust diagnostics improved by extraneous arguments fix 2019-10-16 10:19:26 -07:00
Pavel Yaskevich
51476cde58 [Diagnostics] Clarify tuple splat message when single parameter is generic parameter
Since it's hard to say whether tuple use is really intended, let's
add `did you mean to pass a tuple?` note to the error message.
2019-10-09 10:58:31 -07:00
Pavel Yaskevich
c62c2890f8 [Diagnostics] Fix fix-it location for labeled tuple splat
In situations like this:

```swift
func foo(x: (Int, Int) {}
foo(x: 0, 0)
```

Left paren to form a missing tuple should be placed after
the label because belongs to the parameter and not the tuple.
2019-10-08 18:12:17 -07:00
Pavel Yaskevich
7e6b4e4d57 [Diagnostics] Extend single parameter tuple splat to support generic parameters
Currently single parameter tuple splat fix/diagnostic supports only
cases where parameter is a concrete tuple type, let's enhance that to
support generic parameters as well e.g.:

```swift
func foo<T>(_: T) {}
foo(0, 1, 2) // `T` expects arguments to form a tuple e.g. `foo((0, 1, 2))`
```
2019-10-08 18:11:48 -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
ec6a874ac8 [TypeChecker] NFC: Update test-cases improved by new missing arguments diagnostic 2019-09-25 10:47:26 -07:00
Slava Pestov
0ade7b70d9 AST: Type::subst() preserves TypeAliasType sugar
Fixes <rdar://problem/45313760>.
2019-09-24 17:42:15 -04:00
Pavel Yaskevich
ee8c78eef5 [Diagnostics] Tailored diagnostic when single tuple used instead of N distinct arguments
Diagnose cases when instead of multiple distinct arguments
call got a single tuple argument with expected arity/types:

```swift
func foo(_: Int, _: Int) {}
foo((0, 1)) // expected 2 arguments, got 1 tuple with 2 elements
```
2019-09-23 13:00:37 -07:00
Pavel Yaskevich
a1643d94f7 [Diagnostics] NFC: Update all of the improved test-cases 2019-09-13 22:35:52 -07:00
Pavel Yaskevich
15ae692da0 [ConstraintSystem] Repair and diagnose failures relared to throws mismatch
If the only difference between two functions is `throws` and it
is not a subtype relationship, let's repair the problem by dropping
`throws` attribute and letting solver continue to search for
a solution, which would later be diagnosed.
2019-08-13 11:55:08 -07:00
Pavel Yaskevich
9969582cc3 [Diagnostics] Adjust single parameter splat message to prefix substitutions with with 2019-07-16 12:58:10 -07:00
Pavel Yaskevich
0dc863313c [Diagnostics] Extend single parameter splat diagnostic to report substitutions 2019-07-16 11:06:42 -07:00
Pavel Yaskevich
9550d10037 [Diagnostics] Add a diagnostic for single parameter tuple splat
Diagnose situation when a single "tuple" parameter is given N arguments e.g.

```swift
func foo<T>(_ x: (T, Bool)) {}
foo(1, false) // foo exptects a single argument of tuple type `(1, false)`
```
2019-07-16 11:06:42 -07:00
Slava Pestov
663fa09053 Sema: Replace existing noescape checks in favor of using TVO_CanBindToNoEscape 2019-04-16 23:01:39 -04:00
Slava Pestov
7d2c5e1b36 Sema: Don't 'tuple splat' parameter lists with @autoclosure parameters
Fixes <https://bugs.swift.org/browse/SR-9991>.
2019-04-16 22:10:22 -04:00
Slava Pestov
0502f3b22e Slim down test/Compatibility/tuple_arguments_4.swift 2019-04-16 22:10:22 -04:00
Slava Pestov
39a22f3d6a AST: Remove ParameterTypeFlags::Escaping
Escapingness is a property of the type of a value, not a property of a function
parameter. Having it as a separate parameter flag just meant one more piece of
state that could get out of sync and cause weird problems.

Instead, always look at the noescape bit in a function type as the canonical
source of truth.

This does mean that '@escaping' is now printed in a few diagnostics where it was
not printed before; we can investigate these as separate issues, but it is
correct to print it there because the function types in question are, in fact,
escaping.

Fixes <https://bugs.swift.org/browse/SR-10256>, <rdar://problem/49522774>.
2019-04-15 00:25:03 -04:00
David Zarzycki
31d8153097 [Sema] QoI: Report all tuple type resolution errors
This improves single pass diagnostics when more than one tuple type
element has problems.
2019-03-11 16:03:17 -04:00
Pavel Yaskevich
502e88deff [CSSimplify] Tuple splat should account for single dependent member parameters
12a65fffee restricted tuple splat
to a single tuple or type variable parameter, but it has to
support dependent member types as well because they could be
resolved to `Void` (or empty tuple).

Resolves: rdar://problem/48443263
2019-02-27 12:20:11 -08:00
Slava Pestov
6d19f7e0f4 Sema: Fix inconsistent behavior with SE-0110-related compatibility hack
Back when SE-0110 was implemented we decided that passing a function value
taking multiple parameters would be allowed where a function value taking
a single tuple argument was expected.

Due to quirks in the old function type representation, the "splat" in the
other direction sometimes worked too. When we redid the function type
representation we added a simulation of the old quirk for -swift-version 4
mode.

However this simulation was itself problematic because it only worked when
the function value being passed was a non-overloaded declaration reference.

Slightly broaden the hack to the overloaded case, to prevent user
confusion when adding or removing overloads.
2019-02-21 09:57:03 -05:00