Commit Graph

1064 Commits

Author SHA1 Message Date
John McCall
5519749ade [NFC] Collect protocol decls, not type, in ExistentialLayout
Another thing that will be necessary for correctness with
compositions of parameterized protocols.
2022-04-11 22:15:16 -04:00
Pavel Yaskevich
613fdca3a8 [CSDiagnostics] Fix trailing closure ambiguity note to not expect that anchor is expression
`TrailingClosureAmbiguityFailure::diagnoseAsNote()` is used by
`diagnoseAmbiguity` opportunistically, which means that anchor
could be a pattern or a statement condition element.
2022-03-17 12:20:23 -07:00
Pavel Yaskevich
e94abe4557 Merge pull request #41847 from xedin/add-missing-locator-simplifications
[ConstraintSystem] Implement simplification for all locator elements
2022-03-17 09:52:06 -07:00
Pavel Yaskevich
2c35b651f4 [CSDiagnostics] Adjust a couple of diagnostics to not respect different anchor kinds 2022-03-17 00:51:25 -07:00
Pavel Yaskevich
6fb5c3042b [CSDiagnostics] Contextual failure could result in optional chain having non-optional type
Fixes a crash during diagnostics by not assuming that optional chain
would always produce an optional type, which is not true because in
error scenarios it could get assigned an invalid type from context.

Resolves: rdar://85516390
2022-03-15 13:14:48 -07:00
Holly Borla
12459cff80 [Diagnostics] Print 'any' in diagnostic arguments. 2022-03-05 14:26:45 -08:00
Pavel Yaskevich
5ec5ffcfda Merge pull request #41570 from xedin/add-expr-pattern-handling-to-solver
[ConstraintSystem] Add support for expression patterns
2022-02-28 09:39:26 -08:00
Anthony Latsis
f2b3e7bf9e CSDiag & ConformanceChecker: Resolve type witnesses before value witnesses ContextualFailure::tryProtocolConformanceFixIt 2022-02-25 23:40:45 +03:00
Pavel Yaskevich
50d0508a4b [ConstraintSystem] Add a new contextual type purpose - expression pattern
This makes it possible to associate expression with its parent pattern.
2022-02-25 12:30:22 -08:00
Pavel Yaskevich
8cfdb9999c Merge pull request #41436 from xedin/allow-specialization-from-default-expr
[TypeChecker] Allow inference from default expressions in certain scenarios (under a flag)
2022-02-24 08:57:42 -08:00
Anthony Latsis
f239dbcf54 [SE-309] CSDiag: Add a fix-it that replaces an existential parameter type with its generic equivalent 2022-02-23 10:24:54 +03:00
Pavel Yaskevich
82b955b93c [CSDiagnostics] Detect and diagnose contextual mismatches with default value 2022-02-21 09:59:54 -08:00
Pavel Yaskevich
c2831cd2a9 [CSDiagnostics] Adjust generic requirement diagnostics for inference from defaults
Contextual type could be a type variable or a type with type variables
that have a set of generic requirements, so affected declaration is
the owner of the generic parameter.
2022-02-21 09:59:53 -08:00
Pavel Yaskevich
ef570d1a86 Merge pull request #41226 from xedin/rdar-88256059
[CSDiagnostics] Diagnose ambiguous empty closures
2022-02-05 08:38:58 -08:00
Pavel Yaskevich
94188b87f6 [CSDiagnostics] Diagnose ambiguous empty closures
- Allow `SpecifyClosureReturnType` to be diagnosed in ambiguous context
- Add a tailoed diagnostic for when it's impossible to infer a type of
  an empty closure

Resolves: rdar://88256059
2022-02-04 20:33:12 -08:00
Nuri Amari
fda0b8053d Merge pull request #40903 from NuriAmari/default-diagnostics
Enable lazy ClangImporter diagnostics by default
2022-02-04 11:42:47 -05:00
Anthony Latsis
c7fd60f2dd Merge pull request #39492 from AnthonyLatsis/se-309-2
SE-309: Covariant erasure for dependent member types
2022-02-02 07:07:17 +03:00
Nuri Amari
7ec861fbd9 Enable lazy ClangImporter diagnostics by default
Replace the existing `-enable-experimental-clang-importer-diagnostics`
flag with an opt-out version entitled `-disable-experimentalc-clang-importer-diagnostics`.
Enable the beviour previously hidden behind the old flag by default.
2022-02-01 18:43:49 -05:00
Anthony Latsis
c47f99a22d Diag: Use 'Self'-rooted interface types instead of opened archetypes in requirement failure messages 2022-02-02 02:10:05 +03:00
Anthony Latsis
8e0e4146b2 Diag: Silence argument mismatch failures in unsupported existential member accesses 2022-02-02 02:10:05 +03:00
Nuri Amari
3762ca1fa7 Attach Lazy ClangImporter Diagnostics as Notes
Clang importer diagnostics that are produced as a result of a reference
in Swift code are attached to as notes to the Sema produced diagnostic
that indicates the declaration is unavailable.

Ex: Notes about why a C function import failed are attached to
the error explaining that the symbol could not be found in scope.
2022-01-29 14:32:42 -05:00
Holly Borla
5dced8e5f9 [ConstraintSystem] Fix a few constraint system corner cases with explicit
existential types.
2022-01-13 19:30:44 -08:00
Cal Stephens
b1ebd95ed0 Improve diagnostic for invalid use of implicit self before self is unwrapped 2021-12-23 19:27:05 -08:00
Robert Widmann
d44d8ec043 Allow Converting Pack Types to Tuples
Insert an implicit conversion from pack types to tuples with equivalent parallel structure. That means

1) The tuple must have the same arity
2) The tuple may not have any argument labels
3) The tuple may not have any variadic or inout components
4) The tuple must have the same element types as the pack
2021-12-16 08:51:38 -08:00
Pavel Yaskevich
0e6e058e7c [TypeChecker] Fix constraint solver to respect LeaveClosureBodyUnchecked flag 2021-12-03 10:54:07 -08:00
Doug Gregor
c0f5502269 Leverage error-to-warnings downgrades for non-ephemeral conversion diagnostics
There were slight wording changes between the warning and error
diagnostics, but they don't seem to justify the duplication here.
2021-12-02 11:12:07 -08:00
Doug Gregor
365f0afa9f Downgrade concurrency-related function type errors in existing code
When in "existing" Swift code that is Swift 5.x and has not adopted
concurrency, allow mismatches in function types that only involve
ABI-neutral concurrency changes (e.g., adding `@Sendable` or removing
a global actor) by downgrading the diagnostic to a warning. This
improves the story for incremental adoption of concurrency in an
existing code base.

As part of this, generalize the facility for downgrading an error to a
warning when performing diagnostics in the constraint solver, using the
new diagnostic behavior limits rather than duplicating diagnostics.
2021-12-02 10:33:01 -08:00
Pavel Yaskevich
bc54bc6bb7 Revert "[TypeChecker] SE-0326: Enable multi-statement closure inference by default" 2021-11-29 17:26:08 -08:00
Xi Ge
03c76bd32d sema: diagnose passing a non-constant value into a constant parameter 2021-11-22 11:52:57 -08:00
Hamish Knight
237338b504 Merge pull request #40224 from hamishknight/super-tuple-shuffle 2021-11-18 09:50:09 +00:00
Hamish Knight
4aaec65780 [CS] Warn on mismatched tuple labels for subtyping
This is something that we'd like to fix to bring
in line with tuple conversion, so start warning on
cases where it occurs.
2021-11-17 17:06:21 +00:00
Pavel Yaskevich
83033198c3 [TypeChecker] Fix constraint solver to respect LeaveClosureBodyUnchecked flag 2021-11-15 16:42:05 -08:00
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
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