Commit Graph

2385 Commits

Author SHA1 Message Date
Pavel Yaskevich
c9ef0056dc Merge pull request #35072 from xedin/rdar-72166791
[Diagnostics] Special case assignment between nominal types with optional promotion
2020-12-14 11:54:59 -08:00
Nate Cook
c35b567001 Temporary removal of RangeSet/DiscontiguousSlice (#35076) 2020-12-14 08:42:01 -06:00
Pavel Yaskevich
ec31d77fa6 [Diagnostics] Allow integer cast fix-its for assignment mismatches 2020-12-11 20:49:54 -08:00
Pavel Yaskevich
0e6260dd89 [Diagnostics] Special case assignment between nominal types with optional promotion
Skip fixing situation where source and destination of assignment are both
nominal types with different optionality until restriction is attempted.

Otherwise fix could be too greedy and diagnose valid code if all of the
types are known in advance.

Resolves: SR-13951
Resolves: rdar://problem/72166791
2020-12-11 20:49:43 -08:00
Pavel Yaskevich
a046eaf477 [ConstraintSystem] Adjust getFunctionArgApplyInfo to respect holes
Detect that direct callee couldn't be resolved e.g. due to an
invalid reference or a missing member and fail instead of
triggering an assert.

Resolves: rdar://problem/71525503
2020-12-07 13:55:57 -08:00
Doug Gregor
50cdddaf95 [Concurrency] Enable implicit conversion from synchronous -> asynchronous. 2020-12-03 12:44:21 -08:00
Doug Gregor
1798e66c6e [Concurrency] Disallow 'async' and non-async overloading. 2020-12-03 09:34:15 -08:00
Pavel Yaskevich
3d91d7f4f2 Merge pull request #34794 from xedin/rdar-71356981
[TypeChecker] Find outermost paren or tuple while checking invalid `i…
2020-12-02 20:44:24 -08:00
Pavel Yaskevich
85181360b1 Merge pull request #34810 from xedin/rdar-66709164
[ConstraintSystem] Detect and diagnose extraneous return(s) in result build body
2020-12-02 15:51:10 -08:00
Holly Borla
1a20cbe3e1 Merge pull request #34918 from xedin/rdar-71858936
[ConstraintSystem] Mark type variable representing closure parameter …
2020-12-02 09:06:55 -05:00
Pavel Yaskevich
5ebba42268 [ConstraintSystem] Mark type variable representing closure parameter (in the body) as incomplete
Restore recently removed logic to mark type variable representing
closure parameter used in the body of a closure as potentially
incomplete to delay attempting it until `BindParam` is simplified.

Resolves: rdar://problem/71858936
2020-12-01 20:35:34 -08:00
Luciano Almeida
19727f2cc2 [Sema][test] Adjusting all missing downcast diagnostics failures 2020-11-28 18:17:18 -03:00
Pavel Yaskevich
8b49e356d8 [ResultBuilders] NFC: Adjust error diagnostic about use of explicit 'return' statement(s) 2020-11-19 17:24:57 -08:00
Pavel Yaskevich
d912e12ba7 [ResultBuilders] Use new fix to detect and diagnose use of return statements in a result builder body 2020-11-19 17:21:00 -08:00
Pavel Yaskevich
607f49dc2e [TypeChecker] Find outermost paren or tuple while checking invalid inout use
Unwrap `InOutExpr` from all parens until the outermost paren or a tuple
to correctly diagnose calls like `foo(((&bar)))` or `foo(x: (&bar))`,
 and suggest a fix-it with moves `&` outside parens.

Resolves: rdar://problem/71356981
2020-11-19 13:31:10 -08:00
Slava Pestov
5808d9beb9 Parse: Remove parse-time name lookup 2020-11-16 22:39:44 -05:00
Nathan Hawes
1105531b7b Merge pull request #34521 from nathawes/handle-dicts-parsed-as-arrays-for-completion
[CodeCompletion][Sema] Add fix to treat empty or single-element array literals as dictionaries when used as such
2020-11-11 15:54:55 -08:00
Nathan Hawes
edbbefce91 [CodeCompletion][Sema] Add fix to treat empty or single-element array literals as dictionaries when used as such
In the single-element case, it is treated as the dictionary key.

func takesDict(_ x: [Int: String]) {}
takesDict([]) // diagnose with fixit to add missing ':'
takesDict([1]) // diagnose with fixit to add missing ': <#value#>'
takesDict([foo.<complete>]) // prioritise Int members in completion results -
                            // the user just hasn't written the value yet.

The above previously failed with a generic mismatch error in normal type
checking (due to the literal being parsed as an array literal) and code
completion could not pick up the expected type from the context.
2020-11-11 11:48:39 -08:00
Pavel Yaskevich
6f739337d3 Merge pull request #34680 from xedin/rdar-71226646
[TypeChecker] NFC: Add one more test-case for SR-13442
2020-11-11 00:33:52 -08:00
Pavel Yaskevich
24b69f5c89 [TypeChecker] NFC: Add one more test-case for SR-13442 2020-11-10 16:04:48 -08:00
Robert Widmann
4dab4c235b Merge pull request #34648 from CodaFi/a-fully-qualified-success
[DiagnosticsQoI] Fully Qualify the Parent Type When Diagnosing Missing Member Types
2020-11-09 21:32:00 -08:00
Robert Widmann
363b66a7ad Fully Qualify the Parent Type When Diagnosing Missing Member Types
Use the FullyQualified<Type> abstraction from the prior commit plus DescriptiveDeclKind to give a bit more information when issuing a missing member type diagnostic during type resolution.
2020-11-09 17:10:18 -08:00
Pavel Yaskevich
d7c6c00e04 Merge pull request #34614 from xedin/improvements-to-ambiguity-diags
[Diagnostic] Improve diagnostics for situations with ambiguity caused by conformance requirements
2020-11-09 16:07:11 -08:00
Holly Borla
a647f0fb5b Merge pull request #34399 from hborla/optimize-linked-operator-solving
[Constraint System] Implement heuristics for linked operator expressions in the solver proper.
2020-11-08 13:22:40 -08:00
Pavel Yaskevich
66fbdce2f8 [ConstraintSystem] Don't increase a score for conditional requirement failures
Let's consider conditional requirement failure to mean that parent
conformance requirement wasn't satisfied and nothing more, that helps
to disambiguate certain situations and avoid filtering out conditional
failures.

Resolves: rdar://problem/64844584
2020-11-06 12:06:00 -08:00
Pavel Yaskevich
fa5c7120ef [ConstraintSystem] Ignore value-to-optional conversions to correctly detect conformance failures
If there is a conformance failure related to existential conversion
let's ignore that fact that there could be an implicit value-to-optional
conversion involved, because it's not the main issue in cases like
that.

Resolves: rdar://problem/70814576
2020-11-03 15:51:55 -08:00
Mohammed Al-Dahleh
15d566d4ab SR-13759: FixIt - Insert await on async (#34509) 2020-11-03 08:50:08 -08:00
Holly Borla
423d6bdff0 [ConstraintSystem] Re-instate the operator type variable merging
hacks for now.

There's some more disjunction pruning work to be done before we can
remove this.
2020-10-29 19:49:47 -07:00
Slava Pestov
ae5bca927a Sema: Check result builder availability 2020-10-29 14:00:04 -04: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
John McCall
a8464dcaf1 Implicitly import _Concurrency under -enable-experimental-concurrency 2020-10-22 00:53:15 -04:00
Doug Gregor
6d41524fe6 [SE-0289] Finish renaming source code, tests to "result builders" 2020-10-20 22:18:51 -07:00
Doug Gregor
0d568a93d4 [SE-0289] Update diagnostics & many other strings to "result builders" 2020-10-20 21:44:09 -07:00
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