Commit Graph

756 Commits

Author SHA1 Message Date
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
Pavel Yaskevich
d7e0971764 Merge pull request #36531 from LucianoPAlmeida/SR-14096-kp-as-fn
[Sema][SR-14096] Change conditions in which key path component mismatch fix are diagnosed
2021-03-22 10:42:08 -07:00
Luciano Almeida
0bca6ce73c [Sema] Do not skip key path last component/value equal constraint failure fix 2021-03-21 18:29:47 -03:00
Doug Gregor
52096a640e SE-0302: Rename ConcurrentValue/@concurrent to Sendable/@Sendable. 2021-03-18 23:48:21 -07:00
Pavel Yaskevich
1dd914a651 Merge pull request #36445 from xedin/rdar-75367157
[Diagnostics] Check whether missing conformance could be fixed by using `.rawValue`
2021-03-17 15:24:33 -07:00
Doug Gregor
d6fc1fd60f Implement conversions for global-actor-qualified functions.
One can convert from a function value without a global actor to a
similar function type that does have a global actor, but one cannot
remove or change a global actor on a function type.
2021-03-17 00:51:26 -07:00
Pavel Yaskevich
8c6017687a [ConstraintSystem] Limit new implicit conversion to only Double <-> CGFloat 2021-03-17 00:18:10 -07:00
Pavel Yaskevich
2b935bab7c [ConstraintSystem] Add conversion restriction to cover implicit conversion from/to CGFloat 2021-03-17 00:18:08 -07:00
Pavel Yaskevich
45c73b30fd [Diagnostics] Even though missing conformance could be fixed by .rawValue still diagnose it as conformance issue
Conformance requirement failure is a more descriptive error,
augment it with a note about missing `.rawValue`.
2021-03-17 00:14:51 -07:00
Pavel Yaskevich
e92c6eb68c [Diagnostics] NFC: Use non-initializer diagnostic when raw representable type doesn't conform but .rawValue does 2021-03-15 17:29:31 -07:00
Pavel Yaskevich
2a9903dfe4 [Diagnostics] Check whether missing conformance could be fixed by using .rawValue
A lot of operators (and most likely regular functions a well) have
overloads that accept i.e. a generic parameter that conforms to
`StringProtocol`, so the best fix in situations when argument is
a raw representable type would be to check whether `.rawValue`
conforms to the expected protocol and use it if so.

Resolves rdar://problem/75367157
2021-03-15 16:53:45 -07:00
Pavel Yaskevich
fb89d11931 [ConstraintLocator] NFC: Adjust name of isForKeyPathComponent to clarify its meaning
New name is `isInKeyPathComponent` since it's implemeneted as a
check for presence of `KeyPathComponent` element in the locator
that covers every sub-element contained in a key path component
as well.
2021-03-12 09:58:54 -08:00
Holly Borla
db387273f6 [ConstraintSystem] Don't allow dollar prefixes in argument labels unless
the parameter has an attached property wrapper.
2021-02-25 18:35:14 -08:00
Holly Borla
133dec0e05 [ConstraintSystem] Implement implicit property wrapper attribute
inference for closure parameters.
2021-02-25 18:35:14 -08:00
Holly Borla
522eedcfd1 [ConstraintSystem] Emit an error message when trying to pass a property
wrapper projection argument to a wrapped parameter with arguments in the
wrapper attribute.
2021-02-25 18:35:14 -08:00
Holly Borla
ea3fe03c98 [Property Wrappers] Add a constraint fix and diagnostic for the case
where the programmer tries to pass a projection argument to a wrapped
parameter without 'var projectedValue'.
2021-02-25 18:35:14 -08:00
Pavel Yaskevich
cf5e1fff8d [Diagnostics] Add a tailored diagnostic for contextual lookup on protocols without Self requirement 2021-02-23 11:33:11 -08:00
Pavel Yaskevich
2d8f002299 [CSDiagnostics] Adjacent diagnostics for the new rules of static member lookup in generic context 2021-02-23 11:33:11 -08:00
Pavel Yaskevich
e548366bb5 [TypeChecker] Add tests for static member refs on protocol metatypes feature 2021-02-23 11:33:11 -08:00
Pavel Yaskevich
feb8684dac [Diagnostics] Add a clarifying note about result type for invalid member ref diagnostic 2021-02-23 11:33:10 -08:00
Pavel Yaskevich
03d869ad8b [Diagnostics] Extract invalid result type from overload choice
Instead of threading it through the constraint system all the way
to a diagnostic, let's extract it from overload choice instead.
2021-02-23 11:33:10 -08:00