Commit Graph

2502 Commits

Author SHA1 Message Date
Doug Gregor
6a40a3a8aa [SE-0289] Add support for @resultBuilder.
"Function builders" are being renamed to "result builders". Add the
corresponding `@resultBuilder` attribute, with `@_functionBuilder` as
an alias for it, Update test cases to use @resultBuilder.
2020-10-20 13:24:51 -07:00
Luciano Almeida
907b06901f Merge pull request #34330 from LucianoPAlmeida/SR-13732-crash-invalid
[SR-13732] [Sema] Fix crash on simplifyFix constraint for tuple mismatch
2020-10-16 21:18:22 -03:00
Luciano Almeida
885815227f [tests] Add regression tests for SR-13732 2020-10-16 18:32:30 -03:00
gregomni
e0199f2d98 Add condition for optimizing series of binops that every possible overload is (T,T)->T, with no (T,T)->U 2020-10-15 09:03:45 -07:00
Holly Borla
1e0038c3be [ConstraintSystem] Remove implementation of operator designated types
in the solver.
2020-10-14 16:05:54 -07:00
Slava Pestov
bd36100cb3 Update tests in preparation for disabling parser lookup
I created a second copy of each test where the output changes
after disabling parser lookup. The primary copy now explicitly
calls the frontend with -disable-parser-lookup and expects the
new diagnostics; the *_parser_lookup.swift version calls the
frontend with -enable-parser-lookup and has the old expectations.

This allows us to turn parser lookup on and off by default
without disturbing tests. Once parser lookup is completely
removed we can remove the *_parser_lookup.swift variants.
2020-10-03 09:37:55 -04:00
Pavel Yaskevich
4d0ab13c36 Merge pull request #34089 from xedin/nil-as-a-hole
[Diagnostics] Diagnose cases when it's impossible to infer type for `nil` literal
2020-09-28 12:13:25 -07:00
Doug Gregor
bec0aae7e5 [Function builders] Add support for function builders on stored struct properties.
Implements SR-13188, which is part of the function builders proposal
under review.
2020-09-26 21:56:12 -07:00
Pavel Yaskevich
a2b3b54523 [CSGen] Rework constraint generation for nil to avoid failing 2020-09-25 15:01:00 -07:00
Pavel Yaskevich
90e6fd4792 [CSGen] Check whether parent has a contextual type before diagnosing nil use
Before considering `nil` to be used without a context, let's
check whether parent expression (semantic significance of
which is not important) has a contextual type associated with it,
otherwise it's possible to misdiagnose cases like:

```swift
func test() -> Int? {
  return (nil)
}
```
2020-09-23 11:23:54 -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
Doug Gregor
075e7d4b5f [Function builders] Separate out the Fix-It tests.
Testing newlines in Fix-Its does not work well with Windows, so
separate out the Fix-It tests for function builder stubs.
2020-09-16 21:01:07 -07:00
Doug Gregor
3b8656dc6f [Function builders] Add stubs for missing buildBlock and buildLimitedAvailability
The lack of these functions in a function builder is diagnosed in
different places in the type checker. Extend these diagnostics to
provide stubs in the function builder.

Thanks to Suyash for the suggestion!
2020-09-16 16:31:03 -07:00
Doug Gregor
25cd671ed5 [Code completion] Test and fix 'static func' for function builder methods. 2020-09-16 15:12:12 -07:00
Doug Gregor
19cfe21db8 [Function builders] Add Fix-Its for missing build* members in builders.
When a use of a function builder involves a statement kind that the
function builder doesn't support (e.g., if-else), add a note to the
diagnostic that specifies what methods need to be added to the
function builder to support that statement, including Fix-Its with
stub implementations.
2020-09-15 22:32:21 -07:00
Pavel Yaskevich
e885a6df99 Merge pull request #33870 from xedin/rdar-68155466
[ConstraintSystem] Adjust impact of a missing member fix
2020-09-10 12:51:02 -07:00
Pavel Yaskevich
7b0e46bdfa [ConstraintSystem] Adjust impact of a missing member fix
Currently its impact is set to be less than that of a conversion fix,
which is incorrect. Let's adjust that and increase it even farther for
cases where base is `Any` or `AnyObject`. We couldn't do it for `Any`
before because it was used to represent type holes, but it's no longer
the case.

Resolves: rdar://problem/68155466
2020-09-09 11:24:34 -07:00
Doug Gregor
111096236a Merge pull request #33862 from DougGregor/concurrency-async-overloading
[Concurrency] Allow overload 'async' with non-async and disambiguate uses.
2020-09-09 07:38:14 -07:00
Doug Gregor
7ed32b8cee [Concurrency] Add a test for async ranking over optional promotion. 2020-09-08 19:02:32 -07:00
Doug Gregor
f467c0ae5f [Concurrency] Add more tests for async overloading. 2020-09-08 19:00:36 -07:00
Doug Gregor
b5759c9fd9 [Concurrency] Allow overload 'async' with non-async and disambiguate uses.
Allow an 'async' function to overload a non-'async' one, e.g.,

    func performOperation(_: String) throws -> String { ... }
    func performOperation(_: String) async throws -> String { ... }

Extend the scoring system in the type checker to penalize cases where
code in an asynchronous context (e.g., an `async` function or closure)
references an asychronous declaration or vice-versa, so that
asynchronous code prefers the 'async' functions and synchronous code
prefers the non-'async' functions. This allows the above overloading
to be a legitimate approach to introducing asynchronous functionality
to existing (blocking) APIs and letting code migrate over.
2020-09-08 16:51:10 -07:00
Pavel Yaskevich
79a2ab0c8c [ConstraintSystem] Record unable to infer base only if hole originated from affected reference
If base type of a unresolved member reference couldn't be determined
(represented as a hole type), before recording a fix about lack of
contextual information, let's make sure that hole originated in either
base or result type of this reference, otherwise the problem is
contextual e.g. generic parameter, which supposed to act as contextual
type for a reference, couldn't be inferred.
2020-09-07 11:44:51 -07:00
Owen Voorhees
c6a266ef62 Merge pull request #29735 from owenv/multiple-varargs
[SE-0284] Allow Multiple Variadic Parameters in Functions, Subscripts, and Initializers
2020-09-05 11:27:21 -05:00
Pavel Yaskevich
e4f6041dba [ConstraintSystem] Record generic fix if destination of a pointer conversion is invalid
If the right-hand side (destination) of value-to-pointer conversion
is incorrect e.g. base type of member is a hole, let's record
a generic "invalid conversion" failure.

Resolves: rdar://problem/68254165
2020-09-04 13:30:53 -07:00
Pavel Yaskevich
923b1fbedf Merge pull request #33762 from xedin/rdar-65983237
[ConstraintSystem] Extend invalid function body fix to cover constraint generation failures
2020-09-03 12:28:49 -07:00
Pavel Yaskevich
d2f5e63773 [TypeChecker] NFC: Add test-case for rdar://problem/65983237 2020-09-02 11:16:18 -07:00
tbkka
82c43a8ac7 [Dynamic Casting] Allow casts to "more optional" types (#33684)
Generally, casting consistency demands that we be able
to extract anything from an existential that can be put
into that existential.  (Which is why the casting spec
requires that casting permit arbitrary injection and
projection of optionals.)

This particular diagnostic prevented optionals from being
projected back out of existentials:
   let i: Int?
   let a: Any = i  // Inject Int? into Any
   // Error prevents projecting Int? back out of Any
   a as? Int?

This also broke certain uses of Mirror (weak variables get reflected as
optionals stored in Any existentials).
2020-08-31 17:52:22 -07:00
Anthony Latsis
5525a7853a Merge pull request #33663 from AnthonyLatsis/unbound-closure-retty
CSGen: Infer generic arguments for explicit closure result types
2020-08-29 03:46:30 +03:00
Rintaro Ishizaki
c48a676a1c Merge pull request #31679 from Jumhyn/implicit-member-chains-different-types
[SE-0287] [Sema] Implementation for implicit member chains
2020-08-28 10:47:53 -07:00
Pavel Yaskevich
a6c3e6f543 Merge pull request #33658 from xedin/introduce-hole-type
[ConstraintSystem] Introduce a new type to represent a type hole
2020-08-28 10:40:15 -07:00
Anthony Latsis
80560dab25 CSGen: Infer generic arguments in explicit closure result types 2020-08-27 22:17:58 +03:00
Frederick Kellison-Linn
5b5e30b6d7 Implement implicit member chains 2020-08-26 22:42:29 -04:00
Pavel Yaskevich
b4d3237bea [CSDiagnostics] Adjust diagnostics to account that type holes in solution are UnresolvedType 2020-08-26 18:45:17 -07:00
Luciano Almeida
7815ecf2a0 [CSApply] Handle OptionalForce component when is initial component on key path expr 2020-08-25 19:31:02 -03:00
Owen Voorhees
9708247065 [SE-0284] Lift the 1-vararg-per-function restriction
[SE-0284] Add round_trip_parse_gen tests

[SE-0284] Add missing test cases
2020-08-23 21:37:07 -07:00
swift-ci
7daed3cf08 Merge pull request #33570 from DougGregor/function-builders-throw 2020-08-20 17:16:27 -07:00
swift-ci
316475c4ff Merge pull request #33564 from DougGregor/function-builders-remove-build-do 2020-08-20 14:13:54 -07:00
Doug Gregor
d46c4ec5c5 [Function builders] Add support for 'throw' statement. 2020-08-20 12:11:45 -07:00
Doug Gregor
1a90eccbfa [Function builders] Remove test case residue. 2020-08-20 11:52:25 -07:00
Doug Gregor
9ffddc9ba6 [Function builders] Remove buildDo.
"do" blocks will always go through buildBlock().
2020-08-20 11:31:07 -07:00
Pavel Yaskevich
a12ac414a1 Merge pull request #33509 from xedin/rdar-65320500
[FunctionBuilders] Implement graceful handling of pre-check failures
2020-08-18 00:58:15 -07:00
Doug Gregor
9ef0fce7b0 [Function builders] Allow build functions to be declared elsewhere.
Make the lookup of the various `build` functions for function builders
normal, qualified name lookup. This allows (e.g.) the implementation
of many of the 'build' functions to come from a protocol extension,
making function builders more composable. Thank you to @anreitersimon
on the Swift forums for the example!
2020-08-17 15:41:33 -07:00
Pavel Yaskevich
56ef379fb8 [ConstraintSystem] Integrate IgnoreInvalidFunctionBuilderBody into the solver 2020-08-17 12:39:29 -07:00
Slava Pestov
6d84c18ba4 Sema: Check 'where' clause requirements on type witnesses
In the included test case, conformance checking of Wrapper : B would
pick up typealias Foo as a witness for the associated type B.Foo.

However, this typealias Foo is defined in a constrained extension where
T : A, and the underlying type references the associated type A.Foo
on T.

The resulting substitution is invalid when the conformance Wrapper : B
is used in a context where T does not conform to A.

Instead, we should ignore this typealias entirely, since it appears
in an unusable constrained extension.

Fixes <rdar://problem/60219705>, <https://bugs.swift.org/browse/SR-12327>,
<https://bugs.swift.org/browse/SR-12663>.
2020-08-15 01:43:13 -04:00
Luciano Almeida
c0055e778e Merge pull request #33380 from LucianoPAlmeida/SR-13359-subscript-tuple
[SR-13359] [Sema] Tailored diagnostics for missing subscript members on tuple type base
2020-08-11 00:04:18 -03:00
Anthony Latsis
a3340e80b3 [NFC] Add a test where a contextual type is necessary to resolve an EnumElementPattern 2020-08-10 17:15:13 +03:00
Anthony Latsis
792da10925 Revert "Sema: Make type resolution for EnumElementPattern less eager" 2020-08-10 16:02:28 +03:00
Luciano Almeida
e8f1784858 [Diagnostics] Adding member subscript tailored diagnostics fixit to string literals that matches a label of labeled tuples 2020-08-09 23:20:44 -03:00
Luciano Almeida
82fe84a85a [Diagnostics] Restricting member subscript tailored diagnostics to literal within bounds of tuple elements 2020-08-09 22:33:35 -03:00
Luciano Almeida
061e69bcc2 [Diagnostics] Adjusting SR-13359 diagnostic wording and add tests for labeled tuples 2020-08-09 02:10:06 -03:00