Commit Graph

180 Commits

Author SHA1 Message Date
Anthony Latsis
2d899d0e73 AST: Cut down on DescriptiveDeclKind usage in DiagnosticsCommon.def 2025-04-05 12:31:20 +01:00
Hamish Knight
2d7500eda6 [AST] Remove ParenType
Today ParenType is used:

1. As the type of ParenExpr
2. As the payload type of an unlabeled single
   associated value enum case (and the type of
   ParenPattern).
3. As the type for an `(X)` TypeRepr

For 1, this leads to some odd behavior, e.g the
type of `(5.0 * 5).squareRoot()` is `(Double)`. For
2, we should be checking the arity of the enum case
constructor parameters and the presence of
ParenPattern respectively. Eventually we ought to
consider replacing Paren/TuplePattern with a
PatternList node, similar to ArgumentList.

3 is one case where it could be argued that there's
some utility in preserving the sugar of the type
that the user wrote. However it's really not clear
to me that this is particularly desirable since a
bunch of diagnostic logic is already stripping
ParenTypes. In cases where we care about how the
type was written in source, we really ought to be
consulting the TypeRepr.
2024-10-31 11:32:40 +00:00
Pavel Yaskevich
2b11ecbec9 [CSBindings] Limit BindingSet::isViable binding skipping to stdlib collection types
This is follow-up to https://github.com/swiftlang/swift/pull/76487

It's reasonable to coalesce bindings of different kind if they don't
allow implicit conversions like stdlib collection types do.

Resolves: https://github.com/swiftlang/swift/issues/77003
2024-10-21 14:48:45 -07:00
Pavel Yaskevich
815699d21a [Diagnostics] Produce a diagnostic for existential mismatch in same-type constraint
Previously this would result in a fallback diagnostic because
type mismatches associated with `ExistentialConstraintType`
locations weren't handled at all.
2024-08-22 16:51:48 -07:00
Holly Borla
9ba481ad53 [Diagnostics] Clarify the wording of error_in_future_swift_version. 2024-03-01 12:05:51 -08: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
Slava Pestov
290701cb4d Sema: Ban shadowing generic parameters from outer scopes
Code like that is usually indicative of programmer error, and does not
round-trip through module interface files since there is no source
syntax to refer to an outer generic parameter.

For source compatibility this is a warning, but becomes an error with
-swift-version 6.

Fixes rdar://problem/108385980 and https://github.com/apple/swift/issues/62767.
2023-04-25 17:41:23 -04:00
Pavel Yaskevich
b7745b04bd [CSSimplify] Detect and diagnose generic argument mismatches individually
Generic arguments types are not always resolved enough to enable
aggregated mismatch fixes, which means that the solver should be
able to handle standalone generic argument matching constraints
and create a fix per mismatch location to coalesce them during
diagnostics.

Resolves: rdar://106054263
2023-03-04 21:57:53 -08:00
Pavel Yaskevich
c7ba055c38 [ConstraintSystem] Handle ambiguities caused by requirement failures
Aggregate all requirement failures (regardless of kind) that belong
to the same locator and diagnose them as an ambiguity (if there is
more than one overload) or as the singular failure if all solutions
point to the same overload.
2023-01-26 15:55:50 -08:00
Pavel Yaskevich
a796c45e4c [CSSimplify] Diagnose contextual mismatch between fully resolved dependent member types
If a constraint has fully resolved but incorrect (not simplifiable)
dependent member types, let's diagnose that as a contextual mismatch
instead of failing (which sometimes leads to a fallback diagnostic).

Resolves: rdar://101412179
2022-10-21 22:28:31 +01:00
Anthony Latsis
06be02636c Gardening: Migrate test suite to GH issues: Constraints (3/5) 2022-08-18 05:36:07 +03:00
Hamish Knight
4915513387 [CS] Filter out uncallable vars when simplifying applied overloads
This improves diagnostics as we can now consider
functions that don't line up exactly with the
argument list if no other viable candidates exist.
2022-07-26 12:51:53 +01:00
Anthony Latsis
ad7df14825 Add regression test to close #43527 2022-07-09 16:47:55 +03:00
Pavel Yaskevich
f3ff87b6f4 [Diagnostics] Diagnose re-labeling failures in ambiguity conditions
If all solutions point to the same overload choice that needs
re-labeling it's safe to diagnose it as if there was no ambiguity
because the call site is static.
2022-05-13 14:25:14 -07:00
Slava Pestov
dac8d666ee Stop passing -requirement-machine-{abstract,inferred,protocol}-signatures flags in tests
These flags are now no-ops.
2022-05-10 12:56:17 -04:00
Josh Soref
8b89b4c995 Spelling constraints (#42548)
* spelling: availability

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: conditional

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: deferred

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: disambiguate

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: failed

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: interferes

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: magnify

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: occurrences

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: overload

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: redeclarations

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: simplification

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: string

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: the

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

Co-authored-by: Josh Soref <jsoref@users.noreply.github.com>
2022-04-22 09:43:26 -07:00
Slava Pestov
75161ce6b0 RequirementMachine: Tweak fixit that turns 'T : Int' into 'T == Int' slightly to match GSB 2022-04-01 01:05:54 -04:00
Holly Borla
12459cff80 [Diagnostics] Print 'any' in diagnostic arguments. 2022-03-05 14:26:45 -08:00
Anthony Latsis
ab6db4fdf6 ProtocolCompositionType: Don't build compositions with a single member and no layout constraint 2022-01-22 18:31:39 +03:00
Anthony Latsis
3c17d35f34 CS: Use TypeResolutionStage::Interface for applying generic arguments in 'openUnboundGenericType' 2021-11-19 16:44:07 +03:00
Pavel Yaskevich
556c74401d [Diagnostics] Ignore result type failures if one side is a hole
If one of the sides in a application result conversion is a hole
it could only mean that the fix has been recorded earlier (at the
point where hole was introduced) and failure at function result
position could be safely ignored.

Resolves: rdar://79757320
2021-07-06 10:29:09 -07:00
Pavel Yaskevich
9e54006cc6 [ConstraintSystem] Don't record a mismatch for synthesized arguments
Without context synthesized argument would be inferred as a hole,
so let's not record any additional fixes for it if there is no way
to infer it properly from a parameter (which could also be a hole
if it is a generic parameter type).

Resolves: rdar://78781552
2021-06-03 16:14:20 -07:00
Pavel Yaskevich
1c3d685fd8 [ConstraintSystem] Simplify relational constraints with the same dependent member type on both sides
If relational constraint has the same dependent member type on both
sides e.g. `$T1.Element == $T1.Element` allow its simplification,
since inference of `$T1` results in dependent member being resolved
to the same concrete type. Otherwise constraint system would be left
with this constraint in inactive state if `$T1` couldn't be resolved
which results in a crash.

Resolves: rdar://78623338
2021-05-28 17:49:55 -07:00
Pavel Yaskevich
46bc3b672d Merge pull request #37115 from xedin/disable-only-in-perf
[CSSimplify] Allow overload choices with missing labels to be considered for diagnostics
2021-04-29 10:25:16 -07:00
Pavel Yaskevich
f36ecf2fa1 [CSSimplify] Allow overload choices with missing labels to be considered for diagnostics
Let's make use of a newly added "disable for performance" flag to
allow solver to consider overload choices where the only issue is
missing one or more labels - this makes it for a much better
diagnostic experience without any performance impact for valid code.
2021-04-28 12:04:57 -07:00
Pavel Yaskevich
40a32dc39a [TypeChecker] NFC: Add a test-case for rdar://77233864 2021-04-27 15:57:55 -07:00
Pavel Yaskevich
39b2ff92b3 [CSStep] Skip disabled overloads only if there are no fixes in diagnostic mode 2021-03-04 15:40:39 -08:00
Pavel Yaskevich
f24e5dbd26 [Diangostics] NFC: Adjust test-cases to expect that "type cannot conform" diagnostic has a note 2020-10-27 14:54:07 -07:00
Pavel Yaskevich
74600db0a4 [TypeChecker] NFC: Add a test-case for fixed rdar://problem/56212087 2020-07-15 20:50:50 -07:00
Onyekachi Ezeoke
434607d004 fix broken tests 2020-06-27 05:53:47 +01:00
Pavel Yaskevich
2164476bf5 [Diagnostics] Port diagnostics related to dictionary literal use 2020-01-13 12:41:07 -08:00
Holly Borla
4fd1377c81 [ConstraintSystem] With the new approach for holes, hole propagation happens
automatically.

This commit also renames `ConstraintSystem::recordHole/isHole` to
`recordPotentialHole` and `isPotentialHole` to make it clear that
we don't know for sure whether a type variable is a hole until it's
bound to unresolved.
2019-11-05 09:15:13 -08:00
Pavel Yaskevich
d90117bb8a [Diagnostics] Remove argument handling from conformance failures
Argument-to-Parameter mismatch handles conformance failures
related to arguments, so the logic in `MissingConformanceFailure`
which wasn't entirely correct is now completely obsolete.

Resolves: rdar://problem/56234611
2019-10-14 00:34:37 -07:00
Pavel Yaskevich
694023ac7c [Diagnostics] Centralize requirement failure impact assessment
Conformance requirements get their fixes attached directly where
other requirements have to use (for now) `repairFailure` mechanism.

Regardless of _how_ fixes get recorded there should be a single
way to assess impact of a particular requirement failure.

The rules are:

- If this is a requirement associated with an operator, impact
  is based on use of the type which failed the requirement;

- If this requirement is from conditional extension,
  it is considered a very high impact because failing such
  requirement makes referenced member de facto invisible.

Resolves: rdar://problem/55593998
Resolves: [SR-11491](https://bugs.swift.org/browse/SR-11491)
2019-09-26 12:13:06 -07:00
Holly Borla
bf80250c84 Merge remote-tracking branch 'upstream/master' into type-cannot-conform-diag 2019-09-17 11:54:03 -07:00
Holly Borla
7687293b7b [Diagnostics] Adjust the description of existential types for the
type_cannot_conform diagnostic message.
2019-09-17 11:52:43 -07:00
Holly Borla
2a7e0099d2 [Diagnostics] Add notes for the type_cannot_conform error that point
to the declaration that requires protocol conformance.
2019-09-17 09:22:07 -07:00
Pavel Yaskevich
a1643d94f7 [Diagnostics] NFC: Update all of the improved test-cases 2019-09-13 22:35:52 -07:00
Holly Borla
40985b6eb7 [Diagnostics] Generalize the "protocol type cannot conform" error to
work for all types that cannot conform to protocols.
2019-09-13 14:51:17 -07:00
Hamish Knight
dba850f16c [CSDiagnostics] Use getAnchormostCalleeLocator
Have FailureDiagnostic::getChoiceFor take a ConstraintLocator argument
which is passed through to getAnchormostCalleeLocator, and rename to
getAnchormostChoiceFor to make the semantics clear. In addition, add
a convenience getAnchormostChoice member for the common case of getting
the choice for the anchor of the failure's locator.

This change means we can now resolve callees for failures associated
with key path subscript components.

Resolves SR-11435.
2019-09-09 14:14:35 +01:00
Hamish Knight
ef1d5ab373 [CS] Look at the fn's rvalue type in getCalleeLocator
This makes sure we correctly resolve to the initialiser decl rather than
an lvalue local variable of a metatype in the included test case.
2019-08-27 15:59:08 +01:00
Pavel Yaskevich
cbadd7ffc2 [Diagnostics] Correctly identify location of requirement failure
Previously in situations like:

```swift
protocol P {}

struct S<T: P> {
  var value: T
}

_ = S(value: 42)
```

Diagnostic has reported a problem as related to "reference" to `init`
but the failing generic type requirement belongs to `S`, so a
better diagnostic in such case should mention `generic struct S`.
2019-08-16 22:02:37 -07:00
Pavel Yaskevich
44f82f256f [TypeChecker] Adjust some of tests improved/regressed after removal of UR_LabelMismatch 2019-07-25 00:36:00 -07:00
Pavel Yaskevich
731ec39c24 [CSStep] Properly finalize component step without follow-up steps
Currently finalization e.g. scope reset and solution minimization
is only done if component step had follow-up e.g. type variable or
disjunction step(s), but it should be done if `take` generated any
fixes as well, or component changed score in any way, otherwise
we might miss some solutions with fixes because "best score" haven't
been reset properly.
2019-07-17 18:04:11 -07:00
Pavel Yaskevich
93ab669c35 [ConstraintSystem] Shrink: If root expression is assignment always consider it as a candidate
If assignment expression is not considered as a top-level candidate
it would mean that other candidates would be allowed to produce
types inconsistent with destination type of the assignment.

Resolves: rdar://problem/51413254
2019-06-24 14:14:14 -07:00
Pavel Yaskevich
a80fa91c3b [ConstraintSystem] Use lightweight conformance check in determining whether literal could be initialized via coercion
Currently logic to transform call into coercion uses `conformsToProtocol`
to validate that type conforms to one of the ExpressibleBy*Literal protocols.

That function doesn't handle unbound generic parameters and would result in
an infinite loop or a crash when not all of the generic parameters were
explicitly specified for one of the types in the chain e.g. `A.B(42)`
where `A` has at least one generic parameter.

Resolves: rdar://problem/50007727
2019-06-11 14:10:37 -07:00
Pavel Yaskevich
6b35f5df4d [TypeChecker] Don't try to validate generic requirements when unbound generic types are involved
If one of the generic parameters is missing let's give solver a
chance to diagnose the problem, otherwise there is a risk of failing
type resolution and not producing any diagnostics.

Resolves: rdar://problem/50099849
2019-05-31 15:14:05 -07:00
Pavel Yaskevich
da799ebe51 [Diagnostics] Add a note if missing parameter is associated with generic subscript 2019-05-30 14:43:37 -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
Hamish Knight
894a1e50bf [CS] Consolidate logic forming locators to callees
This commit adds `ConstraintSystem::getCalleeLocator`, which forms a
locator that describes the callee of a given expression. This function
is then used to replace various places where this logic is duplicated.

This commit also changes the conditions under which a ConstructorMember
callee locator is formed. Previously it was formed for a CallExpr with a
TypeExpr function expr. However, now such a locator is formed if the
function expr is of AnyMetatypeType. This allows it to be more lenient
with invalid code, as well as work with DotSelfExpr.

Resolves SR-10694.
2019-05-16 12:07:40 +01:00