Commit Graph

1026 Commits

Author SHA1 Message Date
swift-ci
a2a6e5a7e8 Merge remote-tracking branch 'origin/main' into rebranch 2021-07-27 02:53:21 -07: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
swift-ci
fd87ebc401 Merge remote-tracking branch 'origin/main' into rebranch 2021-07-23 07:13:34 -07:00
Robert Widmann
d86551de67 Lift Requirement and Parameter Accessors up to GenericSignature
Start treating the null {Can}GenericSignature as a regular signature
with no requirements and no parameters. This not only makes for a much
safer abstraction, but allows us to simplify a lot of the clients of
GenericSignature that would previously have to check for null before
using the abstraction.
2021-07-22 23:27:05 -07:00
swift-ci
a3ebc9a069 Merge remote-tracking branch 'origin/main' into rebranch 2021-07-12 10:51:07 -07:00
Doug Gregor
29f5d7a64a [SE-0302] Implement '@unchecked Sendable' syntax.
Parse and provide semantic checking for '@unchecked Sendable', for a
Sendable conformance that doesn't perform additional semantic checks
for correctness.

Part of rdar://78269000.
2021-07-11 12:29:53 -07:00
swift-ci
e0e2634b84 Merge remote-tracking branch 'origin/main' into rebranch 2021-07-06 09:35:07 -07:00
OneUpWallStreet
25df5d2c48 Fixed some common grammatical errors in the comments. (#38248) 2021-07-05 01:00:48 -07:00
Evan Wilde
42ff140171 llvm::StringRef equals_lower -> equals_insensitive
The `equals_lower` API was replaced with `equals_insensitive` in llvm
commit 2e4a2b8430aca6f7aef8100a5ff81ca0328d03f9 and
3eed57e7ef7da5eda765ccc19fd26fb8dfcd8d41.

Ran git clang-format.

(cherry picked from commit e21e70a6bf)
2021-07-02 10:55:17 -07:00
Luciano Almeida
7f085082dd Merge pull request #38153 from JiarenWang/wjr
[SR-14824] Improve diagnostic for multi-statement closures instead of…
2021-07-01 08:56:10 -03:00
Luciano Almeida
0519dd7cab [Sema] Adjustments on implementation and diagnostic message for SR-14720 2021-06-30 06:39:04 -03:00
Luciano Almeida
51ee1de6f9 [Sema] Adjust escapeness function parameter diagnostic to use decl description 2021-06-30 06:39:04 -03:00
Luciano Almeida
48792bbfdc [Sema] Add tailored diagnostic for a escapeness mismatch in a fn type parameter position 2021-06-30 06:39:04 -03: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
2b58a75f97 [Diagnostics] Fix requirement note to properly handle layout requirements
Layout requirement doesn't have a second type since it's always `AnyObject`,
requirement failure note should handle that, otherwise in no assertion builds
this would crash in diagnostic engine trying to emit the note.

Resolves: rdar://79672230
2021-06-25 14:08:43 -07:00
Pavel Yaskevich
51fe32dc1a [Diagnostics] NFC: Remove unused last argument from requirement failure notes 2021-06-25 13:44:30 -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
fc982aec83 [Diagnostics] Use signed integer to store difference in optionality between types
For checked cast coercion warnings let's store difference in optionality
as an `int` because it's possible that "to" type is more optional than
"from" type.
2021-06-21 13:31:59 -07:00
Pavel Yaskevich
0d50593f68 [Diagnostics] NFC: Fix a typo in a method name: wrapedTypes -> wrappedTypes 2021-06-21 13:31:59 -07:00
Pavel Yaskevich
b4c873aa55 Merge pull request #37941 from LucianoPAlmeida/SR-14784-diag
[SR-14784][Sema] Make sure we look through optionals on anchor fnType for MissingCallFailure
2021-06-16 09:55:11 -07:00
Luciano Almeida
33e47c1e6b [Sema] Make sure we look through optionals on anchor fnType for MissingCallFailure 2021-06-15 23:41:11 -03:00
Pavel Yaskevich
7089b35bcf [AST] NFC: Clarify when extension type repr wouldn't be available 2021-06-14 17:56:40 -07:00
Pavel Yaskevich
a7988b0633 [Diagnostics] Make sure extension type repr is available before using it
Before suggesting to add `where Self == ...` condition to the extension
of a protocol involved in a static member lookup, let's check whether
type repr is available and valid.

Resolves: rdar://78097387
2021-06-14 17:56:16 -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
Hamish Knight
46fa6e5721 [AST] Improve BinaryExpr
Abstract away the TupleExpr gunk and expose
`getLHS` and `getRHS` accessors. This is in
preparation for completely expunging the use
of TupleExpr as an argument list.
2021-05-19 14:48:01 +01:00
Slava Pestov
131d3f4bce Sema: Pass down a ModuleDecl instead of a DeclContext to conformsToProtocol()
... and a bunch of follow-up simplifications pushing ModuleDecls further
up, since I couldn't resist the yak shave.
2021-05-17 16:34:18 -04:00
Holly Borla
e1591314cf Merge pull request #37380 from hborla/property-wrapper-inference-crash
[ConstraintSystem] Fix a constraint system crash with property wrapper inference using the $ syntax.
2021-05-12 08:55:51 -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
c346bbd514 [Diagnostics] Point out where anonymous closure parameters are used in a multi-statement closure 2021-05-11 15:07:44 -07:00
Pavel Yaskevich
493ad7c8fa [Diagnostics] NFC: Re-phrase reference to unused closure parameter in extraneous arguments diagnostic 2021-05-11 15:07:17 -07:00
Pavel Yaskevich
af3dcf0b12 [Diagnostics] Add a tailored note for passing nil to incompatible argument position
New note mentions both expected argument type and its position
and anchors to the affected overload choice.
2021-05-05 11:00:57 -07:00
Pavel Yaskevich
c842773450 [Diagnostics] Re-phrase note about inferred async effect from an operation in a closure body 2021-05-04 10:09:03 -07:00
Pavel Yaskevich
886a8ab6b7 [Diagnostics] Improve diagnostics when passing async to a sync parameter
If `async` effect has been inferred from the body of the closure,
let's find out the first occurrence of `async` node and point it out
to make it clear why closure is `async`.

Resolves: rdar://70610141
2021-05-03 11:08:36 -07:00
Pavel Yaskevich
71372bce67 [Diagnostics] Switch to use contextual purpose associated with locator
`ContextualFailure` is the main beneficiary of additional information
associated with `ContextualType` element because it no longer has to
query solution for "purpose" of the contextual information.

Resolves: rdar://68795727
2021-04-26 09:51:25 -07:00
Pavel Yaskevich
51ff12d06e [ConstraintLocator] Augment ContextualType element to carry its purpose
Having purpose attached to the contextual type element makes it much
easier to diagnose contextual mismatches without involving constraint
system state.
2021-04-26 09:51:21 -07:00
Strieker
4e2b67cbae [NFC] Resolved merge conflict in CSSimplify.cpp after making changes to improve error handling for composed wrapped value mismatches 2021-04-22 11:49:21 -07:00
Strieker
11efb7d0b3 [Diagnostics] Added new diagnostic error string for composed property wrapper mismatch in DiagnosticsSema.def and made changes to show the new composed property wrapper mismatch type diagnostic in both CSDiagnostics.cpp and CSDiagnostics.h. 2021-04-22 11:31:41 -07:00
Azoy
9ed732f0ab Introduce isDecl and getDeclType
fix enum logic issue

fix tests

guard against null types
2021-04-20 02:22:16 -04: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
df8113b5dd [Diagnostics] Contextual mismatch should be attached to the closure if its body is empty/implicit
If there is a contextual mismatch associated with a closure body,
make sure that the diagnostic is attached to the closure even
if the body is empty or implicit.

Resolves: rdar://52204608
2021-04-07 10:06:34 -07:00
Alex Hoppen
fd8e34913a Merge pull request #36551 from ahoppen/pr/internal-labels-in-closures
[CodeComplete] Default parameter names of completed closure to internal names
2021-04-06 15:30:26 +02:00
Alex Hoppen
865e80f9c4 [CodeComplete] Default parameter names of completed closure to internal names
If have a function that takes a trailing closure as follows
```
func sort(callback: (_ left: Int, _ right: Int) -> Bool) {}
```
completing a call to `sort` and expanding the trailing closure results in
```
sort { <#Int#>, <#Int#> in
  <#code#>
}
```

We should be doing a better job here and defaulting the trailing closure's to the internal names specified in the function signature. I.e. the final result should be
```
sort { left, right in
  <#code#>
}
```

This commit does exactly that.

Firstly, it keeps track of the closure's internal names (as specified in the declaration of `sort`) in the closure's type through a new `InternalLabel` property in `AnyFunctionType::Param`. Once the type containing the parameter gets canonicalized, the internal label is dropped.

Secondly, it adds a new option to `ASTPrinter` to always try and print parameter labels. With this option set to true, it will always print external paramter labels and, if they are present, print the internal parameter label as `_ <internalLabel>`.

Finally, we can use this new printing mode to print the trailing closure’s type as
```
<#T##callback: (Int, Int) -> Bool##(_ left: Int, _ right: Int) -> Bool#>
```

This is already correctly expanded by code-expand to the desired result. I also added a test case for that behaviour.
2021-04-01 19:14:19 +02:00
Pavel Yaskevich
f00c578761 Merge pull request #34401 from xedin/implicit-cgfloat-conversion
[DNM][TypeChecker] Implement Double <-> CGFloat implicit conversion
2021-03-31 10:20:28 -07:00
Pavel Yaskevich
a51e3da285 [CSGen] Avoid failing due to invalid explicit closure parameters
If closure parameter has an explicit type, type resolution
would diagnose the issue and cache the resulting error type for
future use. Invalid types currently fail constraint generation,
which doesn't play well with result builders because constraint
generation for their bodies happens during solving.

Let's handle invalid parameters gracefully, replace them with
placeholders and let constraint generation proceed.

Resolves: rdar://75409111
2021-03-26 10:38:18 -07:00
Holly Borla
6f4b62a93c Merge pull request #36568 from hborla/property-wrapper-constraint
[ConstraintSystem] Add a property-wrapper constraint to allow for inference of implicit property wrappers
2021-03-24 17:13:51 -07:00
Holly Borla
76c4c3dc3f [Diagnostics] Add back a dedicated fix/diagnostic for using an invalid
type as a property wrapper.
2021-03-24 11:24:21 -07:00
Holly Borla
f05589f6c4 [Diagnostics] Improve diagnostics for passing an invalid projected
value argument.
2021-03-24 11:24:21 -07:00