Commit Graph

490 Commits

Author SHA1 Message Date
Pavel Yaskevich
4343227d19 [Diagnostics] Determine affected elements early in collection element mismatches
Diagnostics cannot assume that solution would always be applied
to the constraint system, so all of the elements affected by the
mismatch have to be determined by the fix.

Resolves: rdar://85021348
2021-11-12 10:10:44 -08:00
Pavel Yaskevich
0c70f5650f Merge pull request #39592 from Jumhyn/contextual-placeholder-followup
Remove default argument from getContextualType
2021-11-08 10:00:36 -08:00
Pavel Yaskevich
84fa8a35e6 [Sema] Fix unused function/variable warnings in no-assertion configuration 2021-10-15 13:22:44 -07:00
Pavel Yaskevich
1c0a306c75 Merge pull request #37956 from xedin/implicit-swift-to-c-ptr-conversions
[TypeChecker] Implement limited set of conversions between Swift and C pointers
2021-10-06 14:35:22 -07:00
Frederick Kellison-Linn
b433724735 Remove default argument from getContextualType 2021-10-05 17:04:54 -04:00
Konrad `ktoso` Malawski
703595e396 [Concurrent] Warnings/errors should use "sendable" not "concurrent"
Resolves rdar://83416205
2021-09-23 12:45:07 +09:00
Pavel Yaskevich
de35114171 [Diagnostics] Add a tailored diagnostic for Swift -> C pointer conversion
Diagnose situations where Swift -> C pointer implicit conversion
is attempted on a Swift function instead of one imported from C header.

```swift
func test(_: UnsafePointer<UInt8>) {}

func pass_ptr(ptr: UnsafeRawPointer) {
  test(ptr) // Only okay if `test` was an imported C function.
}
```
2021-09-20 17:22:26 -07:00
Pavel Yaskevich
a061a966d1 Merge pull request #39251 from xedin/classof-for-fixes
[CSFix] Add support for `classof` for all fixes
2021-09-20 14:33:06 -07:00
Pavel Yaskevich
bd7d2125b7 Merge pull request #39261 from JiarenWang/wjr
[Compiler] add 'value' label for `NSNumber` to prevent roundabout err…
2021-09-16 10:17:38 -07:00
jiaren wang
391c6e07ad [Compiler] add 'value' label for NSNumber to prevent roundabout error message. 2021-09-15 23:23:41 +08:00
Pavel Yaskevich
0a425480d0 [CSFix] NFC: Rename fix/diagnostic for checked casts that always succeed 2021-09-10 13:55:15 -07:00
Pavel Yaskevich
60d931612c [Dignostics] Diagnose weak declarations with non-optional types
Diagnose situations where `weak` attribute is used with a non-optional type
in declaration e.g. `weak var x: <Type>`:

```swift
class X {
}

weak var x: X = ...
```

`weak` declaration is required to use an optional type e.g. `X?`.
2021-09-07 17:36:56 -07:00
Holly Borla
03777c3fc9 [Diagnostics] Remove ContextualFailure::diagnoseMissingFunctionCall.
Instead, always diagnose missing call errors via MissingCallFailure.
2021-09-06 20:05:13 -07:00
Holly Borla
9d0d521457 [Diagnostics] Diagnose associated value pattern matching errors separately
from missing function call errors in `ContextualFailure`.

It doesn't make sense to diagnose pattern matching errors inside of
`diagnoseMissingFunctionCall`, and the code I added to bail out if there
is no explicit function expression broke the pattern matching diagnostics
anyway.
2021-09-06 19:50:00 -07:00
Hamish Knight
8c2b88abc0 [CS] Adopt ArgumentList
- Explicitly limit favoring logic to only handle
unary args, this seems to have always been the
case, but needs to be handled explicitly now that
argument lists aren't exprs
- Update the ConstraintLocator simplification to
handle argument lists
- Store a mapping of locators to argument lists
in the constraint system
- Abstract more logic into a getArgumentLocator
method which retrieves an argument-to-param locator
from an argument anchor expr
2021-09-01 18:40:25 +01:00
Frederick Kellison-Linn
5f07747cb3 [Sema] Diagnose user-specified placeholders which couldn’t be resolved 2021-08-19 14:53:33 -04:00
Pavel Yaskevich
0074adc6fe [Diagnostics] Result Builders: Extract pattern binding and var storage diagnostics into methods 2021-08-13 12:30:16 -07:00
Hamish Knight
21e8a320ec [CS] Better handle paren fix-its for unresolved chains
I missed this case when previously improving the
logic here. As it turns out, using the raw anchor
as the root expression from which to derive parent
information is insufficient. This is because it
may not capture relevant parent exprs not a part
of the fix locator.

Instead, pass down a function that can be used to
derive the parent expressions from the constraint
system's own parent map. Also make sure to assign
to `expr` for the UnresolvedMemberChainResultExpr
case to make sure we correctly check for it as a
sub-expression.

Finally, now that we're looking at more parent
exprs, add logic to handle `try` and `await`
parents, as well as ClosureExprs and
CollectionExprs. I couldn't come up with a test
case for CollectionExpr, as we emit different
diagnostics in that case, but it's probably better
to tend on the side of being more future proof
there.

rdar://81512079
2021-08-04 14:34:24 +01: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
Pavel Yaskevich
51fe32dc1a [Diagnostics] NFC: Remove unused last argument from requirement failure notes 2021-06-25 13:44:30 -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
2a5eea6165 [Diagnostics] NFC: Add asserts to verify from/to types in contextual failure
We have a couple of reports that `ContextualFailure` crashes in
`trySequenceSubsequenceFixIts` even with the check for a valid
stdlib was added, which can only mean that from/to types are
somehow invalid.

Let's add a couple of asserts to verify their presence to aid us
in determining what expressions can cause the problem.
2021-05-21 14:55:17 -07: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
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
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
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
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
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
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
133dec0e05 [ConstraintSystem] Implement implicit property wrapper attribute
inference for closure parameters.
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
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
Pavel Yaskevich
9231acf202 [Diagnostics] Implement a tailored diagnostic for invalid static member refs on protocol metatypes 2021-02-23 11:32:24 -08:00
Frederick Kellison-Linn
e4ea1678dc Rename HoleType to PlaceholderType
HoleType basically served the same purpose as PlaceholderType. This commit unifies the two.
2021-02-16 22:59:19 -05:00
Luciano Almeida
d55eed46e8 [Sema][CSApply] Moving some checked cast diagnostics to a fix format (#34980)
* [Sema] Implementing is runtime check always true diagnostic as a fix

* [AST] Implement getWithoutThrows on function type

* [CSSimplify] Detect that checked cast types conversion is always true and record warning fix

* [test] Some additional test cases for SR-13789

* [Sema] Fixing typo on fix name

* [Sema] Move and adjust the ConditionalCast diagnostics to the fix format

* [Sema] Remove some checked cast diagnostics from check constraints and move to fix

* [Sema] Renaming checked cast coercible types fix

* [Sema] Some adjustments and rewrite on the logic for downcast record fix

* [Sema] Move logic of runtime function type to AllowUnsupportedRuntimeCheckedCast::attempt

* [Sema] Abstract checked cast fix logic to static function and minor adjustments

* [Sema] Renamings from review
2021-02-10 08:31:06 -03:00
Doug Gregor
ba8819eb58 [Concurrent] Introduce concurrent function types.
Introduce `@concurrent` attribute on function types, including:
* Parsing as a type attribute
* (De-/re-/)mangling for concurrent function types
* Implicit conversion from @concurrent to non-@concurrent
- (De-)serialization for concurrent function types
- AST printing and dumping support
2021-01-27 14:22:32 -08:00
Luciano Almeida
c8ea08df78 [Sema] Creating ambiguous base for none member warning diagnostic as a fix 2020-12-05 22:48:09 -03:00
Doug Gregor
50cdddaf95 [Concurrency] Enable implicit conversion from synchronous -> asynchronous. 2020-12-03 12:44:21 -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
Luciano Almeida
ac65e6fcc4 [Sema] Detect if we should use a conditional binding when recording the CoerceToCheckedCast fix 2020-12-01 09:03:17 -03:00
Pavel Yaskevich
03ede7427c [Diagnostics] Diagnose use of one or more return statements in a result builder body 2020-11-19 17:21:00 -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