Commit Graph

185 Commits

Author SHA1 Message Date
Anthony Latsis
4f4141fea8 Frontend: Obsolete -fixit-all and -emit-fixits-path
With `ARCMigrate` and `arcmt-test` removed from clang in
https://github.com/llvm/llvm-project/pull/119269 and the new code
migration experience under way (see
https://github.com/swiftlang/swift-evolution/pull/2673), these options
are no longer relevant nor known to be in use. They were introduced
long ago to support fix-it application in Xcode.

For now, turn them into a no-op and emit a obsoletion warning.
2025-05-07 02:30:30 +01:00
Doug Gregor
0b01b55e73 Remove an old restriction on _ObjectiveCBridgeable conformances.
Historically, we checked against a specific allowlist for a certain set
of types that were allowed to introduce an `_ObjectiveCBridgeable`
conformance in a different module that where the type was defined.
This rigid allow-list isn't really buying us much, but it's getting in
the way of some refactoring for swift-foundation that's changing
the layering. Remove this diagnostic, since it really isn't buying us
much nowadays, and we have the more general warnings about retroactive
conformances to make folks think twice.
2024-02-06 16:09:17 -08:00
Harlan Haskins
4ac34a40ea @retroactive conformance syntax and checking (#36068) 2023-10-20 14:27:03 -07:00
Pavel Yaskevich
58ffca8f74 [ConstraintSystem] Don't produce partially matching note if none of the overloads matched 2023-05-09 14:11:38 -07:00
Anthony Latsis
e57359a5c7 Merge pull request #60591 from AnthonyLatsis/migrate-test-suite-to-gh-issues-4
Gardening: Migrate test suite to GH issues p. 4
2022-08-20 04:53:15 +03:00
Anthony Latsis
7fc8377e1c Gardening: Migrate test suite to GH issues: Constraints (1/5) 2022-08-17 15:21:51 +03:00
Luciano Almeida
ee20fec382 [Sema] Warn about dictionary literal of dictionary type about duplicated keys 2022-08-15 22:54:55 -03:00
Holly Borla
12459cff80 [Diagnostics] Print 'any' in diagnostic arguments. 2022-03-05 14:26:45 -08:00
LucianoAlmeida
4a881739a6 [Diagnostics][Sema] Improving wording same type is check 2022-01-11 22:46:23 -03:00
LucianoAlmeida
57ce024119 [tests] Add regression tests for SR-15161 2021-09-07 01:45:09 -03: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
Luciano Almeida
19727f2cc2 [Sema][test] Adjusting all missing downcast diagnostics failures 2020-11-28 18:17:18 -03:00
Pavel Yaskevich
66fbdce2f8 [ConstraintSystem] Don't increase a score for conditional requirement failures
Let's consider conditional requirement failure to mean that parent
conformance requirement wasn't satisfied and nothing more, that helps
to disambiguate certain situations and avoid filtering out conditional
failures.

Resolves: rdar://problem/64844584
2020-11-06 12:06:00 -08:00
Pavel Yaskevich
ac2305e7f1 [ConstraintSystem] Increase impact of fixes for some conditional requirements
If there is a conditional requirement failure associated with
member/function reference used in a call let's increase a score
of a fix for such failure because it renders member/function
unreachable in current context or with a given set of arguments.
2020-06-12 11:47:04 -07:00
Hamish Knight
d69a42d656 [CS] Preserve compatibility for collection coercions
Previously we could allow some invalid coercions to
sneak past Sema. In most cases these would either
cause crashes later down the pipeline or
miscompiles. However, for coercions between
collections, we emitted somewhat reasonable code
that performed a force cast.

This commit aims to preserve compatibility with
those collection coercions that previously
compiled, and emits a warning telling the user to
use either 'as?' or 'as!' instead.
2020-04-10 10:16:07 -07:00
Hamish Knight
47541d86f7 [CS] Visit all fixed bindings for constraint re-activation
Start visiting transitive fixed bindings for type
variables, and stop visiting adjacencies for
`gatherConstraint`'s `AllMentions` mode.

This improves performance and fixes a correctness
issue with the old implementation where we could
fail to re-activate a coercion constraint, and
then let invalid code get past Sema, causing
either miscompiles or crashes later down the
pipeline.

Unfortunately this change requires us to
temporarily drop the non-ephemeral fix for a couple
of fairly obscure cases where the overload hasn't
yet been resolved. The logic was previously relying
on stale adjacency state in order to re-activate
the fix when the overload is bound, but it's not
connected on the constraint graph. We need to find
a way to connect constraints to unresolved
overloads they depend on.

Resolves SR-12369.
2020-04-10 10:16:07 -07:00
Hamish Knight
b4c13c2c55 [CS] Adjust assessRequirementFailureImpact
- In `simplifyConformsToConstraint`, pass the LHS
type regardless of whether it is a type variable.

- Add the `choiceImpact` onto the impact for
adding a stdlib conformance.

- Treat Any and AnyObject as standard library
types.
2020-03-28 17:03:42 -07:00
Pavel Yaskevich
059a3602f8 [CSBindings] Refactor a check to produce follow-up direct supertype bindings
This is a follow-up to https://github.com/apple/swift/pull/30113
which cased a regression because it was placed under a check which
allows direct supertypes to be inferred if previous (failing) binding
has a supertype as well which has nothing to do with collection
inference.

Let's combine supertype check and inference logic to avoid such
confusion in the future.

Resolves: rdar://problem/60501780
2020-03-16 12:17:55 -07:00
Pavel Yaskevich
f6b7df161c [ConstraintSystem] Increase impact of a missing conformance related to stdlib type
Prioritize type mismatches over conformance failures when stdlib
types are involved because it wouldn't be appropriate to suggest
to add such a conformance, so the problem is most likely related
to something else e.g. other overload choice has a better fix.

Consider following example:

```swift
struct S {
  init(_: Double) {}
  init<T: BinaryInteger>(_: T) {}
}

_ = S(Double("0"))
```

In cases like that it's better to prefer failable initializer
which takes a `String` and returns `Double?` and diagnose a
problem related to missing optional unwrap instead of missing
conformances related to a `String` argument of other `Double`
initializer just because it returns a concrete type.
2020-02-17 16:09:11 -08:00
Pavel Yaskevich
ec3b783380 [Diagnostics] Improve diagnostic for invalid conversion to AnyObject 2020-01-29 00:37:39 -08:00
Pavel Yaskevich
dea79e09c6 [ConstraintSystem] Detect that function type has failures before applying arguments
If a type variable representing "function type" is a hole
or it could be bound to some concrete type with a help of
a fix, let's propagate holes to the "input" type. Doing so
provides more information to upcoming argument and result matching.
2020-01-27 16:53:33 -08:00
Doug Gregor
c744066c52 [Constraint solver] Stop using the "root expression" in failure diagnostics.
We're still using the root expression to find the parent map, but we're not
falling back to it indiscriminately. Use the parent of the anchor (or
appropriate substitute) instead so we have a better handle on which
expression we're diagnosing for.
2019-11-08 21:26:04 -08:00
Pavel Yaskevich
58329e0c27 Revert "[Diagnostics][Qol] SR-11295 Emit diagnostics for same type coercion. " 2019-10-25 01:05:07 -07:00
Luciano Almeida
86ca3454d6 Fixing warning UnnecessaryCoercion tests 2019-10-21 23:11:21 -03:00
Pavel Yaskevich
f09b07be6c [Diagnostics] Extend use of argument mismatch fix to autoclosure parameters
When it comes to `@autoclosure` parameters we only detect and diagnose
mismatches related to invalid implicit conversions to pointer types. But
`@autoclosure` parameters just like regular ones can have type mismatches
as well which can be handled via recently introduced
`argument-to-parameter mismatch` fix.
2019-10-10 13:33:23 -07:00
Pavel Yaskevich
260a482e1e [Diagnostics] NFC: Adjust some binary operator checks to verify exact diagnostic location
If one of the arguments to binary operator is invalid, let's
verify that diagnostic points directly to it.
2019-09-13 22:35:53 -07:00
Pavel Yaskevich
88c39db0c3 [Diagnostics] NFC: Fix improved test-cases related to argument-to-parameter mismatches 2019-09-13 22:35:53 -07:00
Pavel Yaskevich
a1643d94f7 [Diagnostics] NFC: Update all of the improved test-cases 2019-09-13 22:35:52 -07:00
Doug Gregor
34a7515aee [Constraint graph] Use adjacency info for constraint gathering.
This reinstates the use of direct adjacency information when gathering
constraints, effectively reverting
54bdd7b840.
Fixes the regression that commit caused, which is tracked by
rdar://problem/54274245.
2019-08-22 10:15:54 -07:00
Pavel Yaskevich
385fb0c665 [Diagnostics] Make force downcast fix contextual and move it to repairFailures
This way it covers a lot more ground and doesn't conflict with
other fixes.

Another notable change is related to check for IUO associated
with source type, that covers cases like:

```swift
func foo(_ v: NSString!) -> String {
  return v
}
```

Instead of general conversion failure check for IUO enables solver
to introduce force downcast fix.
2019-08-09 01:09:52 -07:00
Pavel Yaskevich
c30845fa74 [ConstraintSystem] Detect and diagnose missing generic arguments
Introduce a fix to detect and diagnose situations when omitted
generic arguments couldn't be deduced by the solver based on
the enclosing context.

Example:

```swift
struct S<T> {
}

_ = S() // There is not enough context to deduce `T`
```

Resolves: rdar://problem/51203824
2019-05-29 16:39:41 -07:00
Pavel Yaskevich
17643a30e0 [ConstraintSystem] Move missing contextual protocol detection to matchExistentialTypes 2019-05-17 12:53:27 -07:00
Pavel Yaskevich
d4e8d583ae Revert "[ConstraintSystem] Use missing conformance fix to diagnose contextual failures" 2019-05-17 12:45:55 -07:00
Pavel Yaskevich
d5c561b44e [ConstraintSystem] Move missing contextual protocol detection to matchExistentialTypes 2019-05-15 15:37:36 -07:00
Brent Royal-Gordon
a72be0fb7d Sort overloads in suggestPotentialOverloads()
When the compiler fails to find an overload with suitable parameter or return types, it often attaches a note listing the available overloads so that users can find the one they meant to use. The overloads are currently ordered in a way that depends on the order they were declared, so swift-evolve would sometimes cause tests involving these diagnostics to fail.

This change emits the list in a textually-sorted order instead. The names were already being sorted as they were inserted into a std::set, so this shouldn’t significantly slow down the diagnostic.
2018-12-12 11:58:57 -08:00
Karoy Lorentey
666a22feff [test] Modernize hashing throughout the test suite 2018-11-29 17:38:29 +00:00
Mark Lacey
d7cf830842 [ConstraintSystem] Add Array as a designated type for + and +=.
Also add overloads for these operators to an extension of Array.

This allows us to typecheck array concatenation quickly with
designated type support enabled and the remaining type checker hacks
disabled.
2018-11-15 21:42:33 -08:00
gregomni
32bacc8980 More complicated as? test. 2018-08-16 14:27:44 -07:00
gregomni
ca48ebf390 Improve type coercion fixits for optional-to-optional conversions. 2018-08-16 09:43:47 -07:00
Mark Lacey
78d83e5703 Use %target-typecheck-verify-swift where possible. 2018-07-26 23:13:43 -07:00
Mark Lacey
9385dbb3fb Fix exponential type checking of tuple literals.
This fixes two easy cases where we would go exponential in type
checking tuple literals.

Instead of generating a conversion to a single type variable (which
results in one large constraint system), we generate a conversion ot
the same type that appears in the initializer expression (which for
tuples is a tuple type, which naturally splits the constraint system).

I experimented with trying to generalize this further, but ran into
problems getting it working, so for now this will have to do.

Fixes rdar://problem/20233198.
2018-03-26 14:46:03 -07:00
Mark Lacey
f08823757a IUO: Generate Optional<T> rather than ImplicitlyUnwrappedOptional<T>.
Stop creating ImplicitlyUnwrappedOptional<T> so that we can remove it
from the type system.

Enable the code that generates disjunctions for Optional<T> and
rewrites expressions based on the original declared type being 'T!'.

Most of the changes supporting this were previously merged to master,
but some things were difficult to merge to master without actually
removing IUOs from the type system:
- Dynamic member lookup and dynamic subscripting
- Changes to ensure the bridging peephole still works

Past commits have attempted to retain as much fidelity with how we
were printing things as possible. There are some cases where we still
are not printing things the same way:
- In diagnostics we will print '?' rather than '!'
- Some SourceKit and Code Completion output where we print a Type
  rather than Decl.

Things like module printing via swift-ide-test attempt to print '!'
any place that we now have Optional types that were declared as IUOs.

There are some diagnostics regressions related to the fact that we can
no longer "look through" IUOs. For the same reason some output and
functionality changes in Code Completion. I have an idea of how we can
restore these, and have opened a bug to investigate doing so.

There are some small source compatibility breaks that result from
this change:
- Results of dynamic lookup that are themselves declared IUO can in
  rare circumstances be inferred differently. This shows up in
  test/ClangImporter/objc_parse.swift, where we have
    var optStr = obj.nsstringProperty
  Rather than inferring optStr to be 'String!?', we now infer this to
  be 'String??', which is in line with the expectations of SE-0054.
  The fact that we were only inferring the outermost IUO to be an
  Optional in Swift 4 was a result of the incomplete implementation of
  SE-0054 as opposed to a particular design. This should rarely cause
  problems since in the common-case of actually using the property rather
  than just assigning it to a value with inferred type, we will behave
  the same way.
- Overloading functions with inout parameters strictly by a difference
  in optionality (i.e. Optional<T> vs. ImplicitlyUnwrappedOptional<T>)
  will result in an error rather than the diagnostic that was added
  in Swift 4.1.
- Any place where '!' was being used where it wasn't supposed to be
  allowed by SE-0054 will now treat the '!' as if it were '?'.
  Swift 4.1 generates warnings for these saying that putting '!'
  in that location is deprecated. These locations include for example
  typealiases or any place where '!' is nested in another type like
  `Int!?` or `[Int!]`.

This commit effectively means ImplicitlyUnwrappedOptional<T> is no
longer part of the type system, although I haven't actually removed
all of the code dealing with it yet.

ImplicitlyUnwrappedOptional<T> is is dead, long live implicitly
unwrapped Optional<T>!

Resolves rdar://problem/33272674.
2018-01-31 12:15:58 -08:00
Max Moiseev
54f79a40d7 Fix tests 2018-01-08 15:46:28 -08:00
Pavel Yaskevich
12980335cd [CSRanking] Fix self types to be unrelated when comparing operator decls
Such declarations should already have self bound as one of the parameters
which would enforce subtype relationship.

Resolves: rdar://problem/36333688
2018-01-05 23:24:24 -08:00
Max Moiseev
5a01af3da8 Merge pull request #13736 from moiseev/rrc-ops
[stdlib] Rearrange + on RangeReplaceableCollection/Sequence once again
2018-01-05 16:04:43 -08:00
Mark Lacey
d3b6d24d80 IUO: Do not short-circuit disjunctions if we had to apply fixes.
There are cases where disjunctions created for IUOs can be solved with
the Optional choice if a fix is applied. We do not want to stop with
this solution as we may be able to solve the constraint system without
a fix by selecting the non-Optional side.

I have opened a JIRA, SR-6626, to investigate one small regression in
diagnostics with this change.
2018-01-04 15:36:34 -08:00
Max Moiseev
9bf8d773ab [stdlib] Rearrange + on RangeReplaceableCollection/Sequence once again 2018-01-04 13:58:45 -08:00
Ben Cohen
9361a6b66f [stdlib] Nest Iterator and Index types for various stdlib types (#13489)
* Nest various top-level Iterator and Index types, and flatten extensions.

* Fix tests from nesting iterator

* Nest Unsafe*BufferPointer.Iterator, extensionify UnsafeBufferPointer

* Degyb LazyCollection

* Nest Flatten iterator and index
2017-12-18 15:27:35 -08:00
Doug Gregor
ba6f605d47 Fix some tests due to Equatable Optional/Array/Dictionary change. 2017-11-27 21:09:50 -08:00
Greg Parker
e8475cc130 Revert "Use conditional conformances to implement Equatable for Optional, Array and Dictionary" 2017-11-15 14:17:22 -08:00