Commit Graph

21 Commits

Author SHA1 Message Date
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
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
d111f119d8 [ConstraintSystem] Detect and diagnose inability to infer type of closure parameter(s)
Detect situation when it's impossible to determine types for
closure parameters used in the body from the context. E.g.
when a call closure is associated with refers to a missing
member.

```swift
struct S {
}

S.foo { a, b in } // `S` doesn't have static member `foo`

let _ = { v in } // not enough context to infer type of `v`

_ = .foo { v in } // base type for `.foo` couldn't be determined
```

Resolves: [SR-12815](https://bugs.swift.org/browse/SR-12815)
Resolves: rdar://problem/63230293
2020-05-15 01:14:30 -07:00
Pavel Yaskevich
07a69c425f [ConstraintSystem] Make variadics work with anonymous closure parameters
Since opening closure body is now delayed until contextual type becomes
available it's possible to infer anonymous parameters as being variadic
based on context and propagate that information down to the closure body.

Resolves: rdar://problem/41416758
2020-02-05 09:35:49 -08:00
Pavel Yaskevich
15c58d19d5 [ConstraintSystem] Detect passing array to variadic argument in function conversions
Initially this problem was only detected and diagnosed for calls.
So let's extend it to function conversions as well e.g.:

```swift
func foo<T>(_: [T]) {}
func bar<T>(_ f: (T...) -> ()) {}

bar { foo($0) }
```
2019-12-03 12:07:15 -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
Pavel Yaskevich
589ebac1b2 [Diagnostics] Lift all restrictions from invalid generic arguments fix expect to optional types
This helps us to better diagnose failures related to generic
requirements like `T == [Int]` as well as protocol compositions,
which require deep equality check.
2019-08-20 10:50:17 -07:00
Pavel Yaskevich
253abad789 [Diagnostics] Port remaining contextual failures (expect associated with nil)
Remove the rest of the obsolete code from `diagnoseContextualConversionError`
and port diagnostic about string indexing to new diagnostic framework.
2019-08-13 14:33:38 -07:00
Owen Voorhees
89eaa1e612 [Diagnostics] Desugar syntax sugared types if they have unresolved types
If a syntax sugared type like Array had an unresolved type, it used to print as `[_]` in diagnostics, which could be confusing.
Instead, desugar these unresolved types before printing, so Array, for example, prints as `Array<_>`.
Currently this only applies to Array, Dictionary, and Optional.
2019-07-03 08:11:31 -07:00
Slava Pestov
3701f745c4 Migrate various Sema tests to Swift 4 2018-06-25 01:02:20 -07:00
Slava Pestov
5d2752f7d2 Run tests with -swift-version 4 by default
Some test now fail, so add an explicit -swift-version 3.
2018-06-19 23:24:19 -07:00
Slava Pestov
1d1517ff06 Sema: Narrow-ish fix for issue with varargs and anonymous closure arguments
This still doesn't work in a number of cases, but fixes a case
that used to work in Swift 3.0 which was affecting the Dollar.swift
library.

Fixes <rdar://problem/29007725>.
2017-01-23 22:46:54 -08:00
David Farler
b7d17b25ba Rename -parse flag to -typecheck
A parse-only option is needed for parse performance tracking and the
current option also includes semantic analysis.
2016-11-28 10:50:55 -08:00
Xi Ge
1e85e1bcd2 Revert "[Fixit] Add a fixit for converting non-trailing closures to trailing closures (#3317)"
This patch needs some polish to fix more false positives found by @rintaro and @lattner
2016-07-02 09:39:07 -07:00
Xi Ge
1886b4ab56 [Fixit] Add a fixit for converting non-trailing closures to trailing closures (#3317)
* [Fixit] Add a fixit for converting non-trailing closures to trailing closures.

* [test] Update test to reflect the added note about converting to trailing closures.
2016-07-02 08:11:58 -07:00
Manav Gabhawala
7928140f79 [SE-0046] Implements consistent function parameter labels by discarding extraneous parameter names and adding _ where necessary 2016-04-06 20:21:58 -04:00
Dmitri Hrybenko
3b04d1b013 tests: reorganize tests so that they actually use the target platform
Most tests were using %swift or similar substitutions, which did not
include the target triple and SDK.  The driver was defaulting to the
host OS.  Thus, we could not run the tests when the standard library was
not built for OS X.

Swift SVN r24504
2015-01-19 06:52:49 +00:00
Ted Kremenek
fad874708e Adjust test cases.
Swift SVN r17964
2014-05-12 22:01:52 +00:00
Doug Gregor
ce3fe3ae92 Implement Ruby-inspired closure syntax.
This commit implements closure syntax that places the (optional)
parameter list in pipes within the curly braces of a closure. This
syntax "slides" well from very simple closures with anonymous
arguments, e.g.,

  sort(array, {$1 > $0})

to naming the arguments

  sort(array, {|x, y| x > y})

to adding a return type and/or parameter types

  sort(array, {|x : String, y : String| -> Bool x > y})

and with multiple statements in the body:

  sort(array, {|x, y|
    print("Comparing \(x) and \(y)\n")
    return x > y
  })

When the body contains only a single expression, that expression
participates in type inference with its enclosing expression, which
allows one to type-check, e.g.,

  map(strings, {|x| x.toUpper()})

without context. If one has multiple statements, however, one will
need to provide additional type information either with context

  strings = map(strings, {
    return $0.toUpper()
  })

or via annotations

  map(strings, {|x| -> String 
    return x.toUpper()
  }

because we don't perform inter-statement type inference.

The new closure expressions are only available with the new type
checker, where they completely displace the existing { $0 + $1 }
anonymous closures. 'func' expressions remain unchanged.

The tiny test changes (in SIL output and the constraint-checker test)
are due to the PipeClosureExpr AST storing anonymous closure arguments
($0, $1, etc.) within a pattern in the AST. It's far cleaner to
implement this way.

The testing here is still fairly light. In particular, we need better
testing of parser recovery, name lookup for closures with local types,
more deduction scenarios, and multi-statement closures (which don't
get exercised beyond the unit tests).



Swift SVN r5169
2013-05-14 05:17:10 +00:00