Commit Graph

1031 Commits

Author SHA1 Message Date
Pavel Yaskevich
573ae9bcac Merge pull request #40047 from xedin/rdar-83056143
[Diagnostics] A tailored diagnostic for Double<->CGFloat conversion via optional chaining
2021-11-04 16:14:58 -07:00
Pavel Yaskevich
7f94bbf29b [AST] NFC: Drop Type from TypeBase::isCGFloatType
This makes naming consistent with other accessors e.g. `isDouble`
2021-11-03 18:09:14 -07:00
Pavel Yaskevich
9acd1d9a17 [Diagnostics] A tailored diagnostic for Double<->CGFloat conversion via optional chaining
Implicit conversion between optional types are not currently supported,
this includes optional chaining:

```
struct S {
  var test: CGFloat
}

func compute(s: Double?) -> Double? {
  return 42
}

func test(s: S?) {
  _ = compute(s?.test) // CGFloat? -> Double? implicit conversion
}
```

Since `S` is optional, `test` ends up optional as well and that
wasn't correctly detected, so solver was allowed to form a correct
solution because `CGFloat` is converted to `Double` inside of
the chain _prior_ to it being wrapped into an optional because
contextual type of `Double` is propagated to the result of the
chain earlier that conversion takes place.

Resolves: rdar://83666783
2021-11-03 14:36:47 -07:00
Pavel Yaskevich
d72871c0e3 [Diagnostics] Coercion warning shouldn't assume that IUO is always optional
In situations like `_ = ... as! Bool!` the `to` type could either
be represented by an optional (default) or unwrapped. Coercion warnings
cannot assume that `to` (even though its IUO) is always represented
as an optional type.

Resolves: rdar://83072606
2021-11-02 13:42:11 -07:00
Mishal Shah
c2fd49cebb Merge pull request #39473 from apple/rebranch
Update swift:main to support llvm-project:stable/20210726 changes (Rebranch merge)
2021-10-11 09:00:51 -07:00
Luciano Almeida
ca8b660a1c Merge pull request #39648 from LucianoPAlmeida/SR-15281-cast
[SR-15281] [Sema] Couple of contextual mismatch and runtime cast diagnostic fixes
2021-10-10 08:03:24 -03:00
LucianoAlmeida
4e689bba5d [NFC] Adjusting comments for clarity 2021-10-09 14:26:21 -03:00
LucianoAlmeida
b517ed3593 [Sema] Suggest for unwrap fix-it instead of coercion if a subtype relation exists with from and to types 2021-10-09 14:26:21 -03:00
Pavel Yaskevich
99a9828a03 [ConstraintSystem] Add a new contextual purpose - CTP_CaseStmt 2021-10-08 10:08:02 -07:00
Pavel Yaskevich
7197fac8f5 [ConstraintSystem] Add a new contextual purpose - CTP_ForEachSequence
A contextual purpose for a sequence expression associated with
`for-in` statement, that decays into a `ConformsTo` constraint
to a `Sequence` or `AsyncSequence` protocol.

Note that CTP_ForEachSequence is almost identical to CTP_ForEachStmt
but the meaning of latter is overloaded, so to avoid breaking solution
targets I have decided to add a new purpose for now.
2021-10-08 10:08:02 -07:00
Pavel Yaskevich
6b2c016350 Merge pull request #35466 from abdulajet/sr-13976
SR-13976: Improve compiler error message: "partial application of ‘mutating’ method is not allowed"
2021-10-07 12:40:36 -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
Abdul Ajetunmobi
f8c737b1ec SR-13976: Improve compiler error message: "partial application of ‘mutating’ method is not allowed” 2021-10-06 19:59:09 +01:00
swift-ci
3f8fea8508 Merge remote-tracking branch 'origin/main' into rebranch 2021-10-06 10:17:29 -07:00
Hamish Knight
b331a45431 [CS] Improve mutability diag for dynamic lookup
Look at the callee locator to add some additional
info to the diagnostic.
2021-10-01 12:54:08 +01:00
Hamish Knight
f045350266 [CS] Clean up dynamic member overload choice checking
Add `OverloadChoice::isAnyDynamicMemberLookup`,
and use it to clean up a couple of places.
2021-10-01 12:54:08 +01: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
3a41f7af5f [ConstraintSystem] Add a new conversion - Swift to C pointers
Following pointer conversions are supported in argument positions (when referencing C/ObjC functions):

- Unsafe[Mutable]RawPointer -> Unsafe[Mutable]Pointer<[U]Int>
- Unsafe[Mutable]Pointer<Int{8, 16, ...}> -> Unsafe[Mutable]Pointer<UInt{8, 16, ...}>
2021-09-20 17:22:25 -07:00
swift-ci
28d0de56a5 Merge remote-tracking branch 'origin/main' into rebranch 2021-09-20 14:33:29 -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
swift-ci
b03e896a3d Merge remote-tracking branch 'origin/main' into rebranch 2021-09-16 10:33:40 -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
swift-ci
a459ff3a77 Merge remote-tracking branch 'origin/main' into rebranch 2021-09-08 16:15:39 -07:00
Pavel Yaskevich
d798d3f711 Merge pull request #39190 from xedin/diagnostics-for-weak-patterns
[ResultBuilders] Properly diagnose `weak` declarations with non-optional type
2021-09-08 16:08:25 -07:00
Pavel Yaskevich
3bbde55052 [ConstraintSystem] Detect and diagnose incorrectly typed weak declarations
All `weak` declarations are supposed to have an optional type.
Detect situations when is not an optional, wrap it as a fix,
and diagnose the problem.
2021-09-08 09:39:54 -07:00
swift-ci
87204b48f9 Merge remote-tracking branch 'origin/main' into rebranch 2021-09-08 04:12:46 -07:00
Hamish Knight
b5bc5141e5 Merge pull request #39192 from hamishknight/a-range-of-arguments
[CS] Store argument list mappings on solutions
2021-09-08 12:00:48 +01: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
swift-ci
08f1ddb51e Merge remote-tracking branch 'origin/main' into rebranch 2021-09-07 11:34:13 -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
Holly Borla
dc10f60198 [ConstraintSystem] Don't attempt missing function call diagnostics if
there is no function expression explicitly written in the source code.
2021-09-06 19:50:00 -07:00
Hamish Knight
ddff9c4c9d [CS] Store argument list mappings on solutions
Roll back argument list mappings in the constraint
system at the end of solver scopes, and copy
argument list mappings into solutions.
2021-09-06 12:54:49 +01:00
swift-ci
cb32b553de Merge remote-tracking branch 'origin/main' into rebranch 2021-09-04 11:32:57 -07:00
Hamish Knight
3e28bbbd2c Update for review feedback
- Remove OriginalArguments in favor of storing the
pre-rewritten argument list, which simplifies things
nicely
- Adopt llvm::indexed_accessor_iterator
2021-09-01 18:40:29 +01: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
swift-ci
5fe1881a91 Merge remote-tracking branch 'origin/main' into rebranch 2021-08-27 21:53:32 -07:00
Rintaro Ishizaki
49547a5378 [NFC][Basic] Import llvm::isa_and_nonnull to 'swift' namespace
Just for convenicence.

* Replace `llvm::isa_and_nonnull` with imported `isa_and_nonnull`
* Repalce some `EXPR && isa<T>(EXPR)` with `isa_and_nonnull<T>(EXPR)`
2021-08-27 11:36:21 -07:00
swift-ci
0a4b07a10c Merge remote-tracking branch 'origin/main' into rebranch 2021-08-20 09:33:58 -07:00
Frederick Kellison-Linn
5f07747cb3 [Sema] Diagnose user-specified placeholders which couldn’t be resolved 2021-08-19 14:53:33 -04:00
swift-ci
6f33655298 Merge remote-tracking branch 'origin/main' into rebranch 2021-08-13 19:53:46 -07:00
Pavel Yaskevich
994f9a9a3d [Diagnostics] Result Builders: Improve diagnostic for unsupported observed vars 2021-08-13 13:42:13 -07:00
Pavel Yaskevich
0074adc6fe [Diagnostics] Result Builders: Extract pattern binding and var storage diagnostics into methods 2021-08-13 12:30:16 -07:00
Pavel Yaskevich
85d203cb34 [Diagnostics] Result Builders: Improve diagnostic for unsupported lazy/wrapped/computed vars 2021-08-13 12:04:06 -07:00
Pavel Yaskevich
67377216de [Diagnostics] Result Builders: Improve diagnostic for uninitialized variable declarations
Resolves: rdar://81532339
2021-08-13 10:41:13 -07:00
swift-ci
2aedbaa7ef Merge remote-tracking branch 'origin/main' into rebranch 2021-08-10 12:13:26 -07:00
Hamish Knight
e82edadee7 Remove some obsolete literal handling logic
We no longer convert literals into constructor
calls in Sema, SILGen emits the necessary calls.
2021-08-06 17:07:22 +01:00
Arnold Schwaighofer
5a83172a55 Merge remote-tracking branch 'upstream/main' into rebranch 2021-08-05 12:04:56 -07:00