Commit Graph

187 Commits

Author SHA1 Message Date
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
Slava Pestov
7566f98a45 Sema: Diagnose enum inheritance clause containing subclass existential
Also, tidy up the code a bit and stop emitting redundant diagnostics for
associated types.

Fixes <https://bugs.swift.org/browse/SR-10232>.
2019-04-01 22:41:16 -04:00
Doug Gregor
69ef7895a8 [Constraint solver] Match argument labels for unresolved member expressions. 2019-03-01 23:11:34 -08:00
Pavel Yaskevich
d4b67bf3f7 [Diagnostics] Improve argument labeling diagnostics
Extend new labeling diagnostics (via fixes) to support
member references and subscripts.
2019-02-21 16:42:56 -08:00
Pavel Yaskevich
ff2510816d [CSDiagnostics] Use correct overload locator when requirement belongs to explicit init ref
Previously the logic to determine path to the selected overload
in such case was simplistic and only checked the name to be
of constructor, but `ConstructorMember` path is formed only if
member reference is a constructor delegation e.g. `self.init` or
`super.init` in an initializer context.
2019-02-20 12:54:27 -08:00
Suyash Srijan
60da82b70d [GSB] [Diag] Constraint to concrete type using ":" should offer a fix-it (#22152)
* [diag] add a diagnostic note for the fixit

* [gsb] emit a diagnostic with fixit to replace ':' with '=='

* [gsb] rename variable

* [gsb] replace dyn_cast with isa

* [test] add a test case

* [test] update tests

* [gsb] emit diagnostic for protocols as well

* [gsb] simplify if statement

* [gsb] rename a variable

* [gsb] Create a helper to remove Self. prefix and add a new test case

* [gsb] simplify checks

* [gsb] move the diagnostic code to finalize()

* [gsb] re-indent

* [gsb] fix a typo

* [gsb] pass values as copy

* [gsb] show a fixit if the subject type is a member type

* [test] update diagnostics in existing tests

* [gsb] check if the subject type has an assoc type decl

* [gsb] use requirement source

* [test] add new tests

* [gsb] use constraint struct and rename to invalidIsaConstraints
2019-02-08 11:02:32 -05:00
Slava Pestov
353b4cc4c4 Sema: Solve Bind constraints involving to two variables of different lvalue-ness
The restriction here only applies to Equal constraints.

Fixes <rdar://problem/45511838>, <https://bugs.swift.org/browse/SR-9068>.
2019-01-12 18:03:01 -05:00
Pavel Yaskevich
a01a70f671 [CSDiagnostics] Fix requirement source lookup to support unresolved members
Resolves: rdar://problem/45692538
2018-10-31 00:06:15 -07:00
gregomni
b7df1ca1df Re-try a failingConstraint during salvage now that attemptFixes is turned on. This enables better missing conforms-to diagnoses. 2018-10-13 20:06:19 -07:00
Pavel Yaskevich
63b802ca88 [AST/Printing] Don't omit empty labels in special names
This makes diagnostics more verbose and accurate, because
it's possible to distinguish how many parameters there are
based on the message itself.

Also there are multiple diagnostic messages in a format of
`<descriptive-kind> <decl-name> ...` that get printed as
e.g. `subscript 'subscript'` if empty labels are omitted.
2018-09-24 18:36:53 -07:00
Pavel Yaskevich
27d0d26222 Revert "[CSDiagnostics] Don't mention special names in requirement diagnostics" 2018-09-21 14:44:04 -07:00
Pavel Yaskevich
02d5401499 [CSDiagnostics] Don't mention special names in requirement diagnostics
Instead of `initializer 'init' of ...` diagnostic should only
mention kind e.g. `initializer of ...` of the declaration
with a special name.
2018-09-21 00:35:21 -07:00
Pavel Yaskevich
3cc613497c [ConstraintSystem] Add same-type requirement fix/diagnostic
Extend new requirement failure diagnostics by adding "same-type"
generic requirement failures.
2018-08-18 13:05:32 -07:00
Pavel Yaskevich
ba085e5bdc [Diagnostics] Improve missing conformance diagnostics for sub-types and members
If generic parameter associated with missing conformance comes
from different context diagnose the problem as "referencing" a
specific declaration from affected type.
2018-08-07 18:55:43 -07:00
Pavel Yaskevich
ad171e05cc [Diagnostics] Improve missing conformance diagnostics by using affected declaration
Instead of simply pointing out which type had conformance failures,
let's use affected declaration instead, which makes diagnostics much
richer e.g.

```
'List<[S], S.Id>' requires that 'S.Id' conform to 'Hashable'
```

versus

```
initializer 'init(_🆔)' requires that 'E' conform to 'Hashable' [with 'E' = 'S.Id']
```

Since latter message uses information about declaration, it can also
point to it in the source. That makes is much easier to understand when
problem is related to overloaded (function) declarations.
2018-08-07 12:59:53 -07:00
Pavel Yaskevich
f15e17a629 [Sema] NFC: reword "only concrete types can conform to protocols" diagnostic 2018-08-03 14:27:00 -07:00
Pavel Yaskevich
c60e5176e0 [Diagnostics] NFC: Add another test-case improve my tracking missing conformances 2018-08-02 21:59:32 -07:00
Pavel Yaskevich
c2bf3d5ba9 [TypeChecker] NFC: Fix all of the diagnostics improved by conformance tracking 2018-08-02 21:55:16 -07:00
Pavel Yaskevich
29e34e66e7 [ConstraintSystem] Diagnose missing conformance requirements via "fixes"
If fixes are allowed let solver record missing protocol conformance
requirements and assume that `conformsTo` constraint is successfully
solved, this helps to diagnose such errors without involving
heavy-weight expression based diagnostics.

Resolves: rdar://problem/40537858
2018-08-02 16:40:34 -07:00
Huon Wilson
be7702e404 [test] Add constraint test for SR-8075. 2018-06-27 22:38:11 +10:00
Matt Diephouse
87aaf10e6b [Diagnostics] Improve error when type parameters aren't equal 2018-06-15 15:08:05 -04:00
Pavel Yaskevich
e6e3c3e226 [CSBindings] Don't try to rank bindings based on number of defaults if they are literal
Number of defaults is a fallback condition if there are no other
differences, but pontential bindings which are literal should always
be ranked lower than anything else because there is a higher chance
that such bindings are wrong because their full set might not have
been resolved yet.

Resolves: rdar://problem/39616039
2018-05-14 12:17:35 -07:00
David Zarzycki
995dec5d82 [Sema] Error if ObjC interop is needed when disabled 2018-05-07 14:43:04 -04:00
Pavel Yaskevich
5f222ec36d [Diagnostics] Improve diagnostics for type parameter requirements
Detect and diagnose failures in constraints representing
type parameter requirements generated by `openGeneric`.

Resolves: rdar://problem/35890334
2018-03-27 00:11:57 -07:00
Pavel Yaskevich
380ea4a671 [CSBindings] Try to infer bindings from related type variables
Attempt to use potential bindings inferred for related types variables
discoverable through 'subtype' constraints, this helps to build a
more precise bindings domain for each type variable.

Resolves: rdar://problem/38159133
2018-03-05 18:53:40 -08:00
Pavel Yaskevich
8c17b925e6 [ConstraintSystem] Add TypeLoc caching to constraint system
This is useful for explicit casts and type expressions, where
type loc and expression types might be different, and allows
constraint solver to avoid setting opened types to expressions
which resolves multiple crashes.
2018-02-13 00:08:56 -08:00
Doug Gregor
4672c11607 Fix up some test cases whose diagnostics changed for the better. 2018-01-25 17:21:35 -08:00
Pavel Yaskevich
5d5872bb83 [CSBindings] Avoid binding type variables to collection types directly
Instead of binding collection types directly let's try to
bind using temporary type variables substituted for element
types, that's going to ensure that subtype relationship is
always preserved.

Resolves: rdar://problem/35541153
2017-12-01 23:04:19 -08:00
Pavel Yaskevich
4317074a9a [ConstraintSolver] Prioritize certain type variables while looking for bindings
Presence of some constraints (Subtype at least) requires a certain
contextual ranking of the type variables associated with them when
it comes to picking bindings, otherwise it might lead to no or
invalid solutions, because only a set of the bindings for the best
type variable is attempted.

Resolves: rdar://problem/22898292
2017-10-03 10:41:35 -07:00
Pavel Yaskevich
695baccc3e Revert "[ConstraintSolver] Prioritize certain type variables while looking for bindings"
This reverts commit 001b09747a.
2017-10-02 17:30:18 -07:00
Pavel Yaskevich
001b09747a [ConstraintSolver] Prioritize certain type variables while looking for bindings
Presence of some constraints (Subtype at least) requires a certain
contextual ranking of the type variables associated with them when
it comes to picking bindings, otherwise it might lead to no or
invalid solutions, because only a set of the bindings for the best
type variable is attempted.

Resolves: rdar://problem/22898292
2017-09-30 14:36:16 -07:00
Michael Ilseman
a7b299b51b [tests] Update tests as String.CharacterView is deprecated 2017-08-11 12:32:39 -07:00
Pavel Yaskevich
bbaa232731 [ConstraintSolver] Fix computeFavoredTypeForExpr not to impose types on the merged binary operators
`LinkedExprAnalyzer` is not always precise in collecting types of expressions,
so let's not try to impose anything upon linked operator expressions, which are
"mergable", except actually merging argument/result types together to help
constraint solver.

Resolves: rdar://problem/27700622
2017-08-10 12:31:17 -07:00
Pavel Yaskevich
e8744af283 [QoI] Improve diagnostics for assignment expression
Currently `visitAssignExpr` always attempts to use type
derived from destination as a contextual type for assignment
source type-checking, which doesn't always lead to better
results.

Resolves: SR-5081
2017-08-02 18:17:49 -07:00
Pavel Yaskevich
bfbbcc1c91 [QoI] Improve diagnostics for misaligned archetypes with the same name in calls
Resolves: rdar://problem/24329052.
2017-08-01 12:17:16 -07:00
Pavel Yaskevich
242006706e [QoI] Improve diagnostics of unsatisfied generic requirements
Fixes a problem related to presence of InOutType in function parameters
which diagnostics related to generic parameter requirements didn't handle
correctly, and improves diagnostics for unsatisfied generic requirements
in operator applications, which we didn't attempt to diagnose at all.

Resolves: rdar://problem/33477726
2017-07-27 15:06:12 -07:00
Doug Gregor
138b0361d2 [Type checker] Don't allow type variables to bind to dependent members.
When a type variable binds to an (unresolved) dependent member type,
it prevents us from inferring the type variable and adds no useful
information to the system. Refuse to bind type variables to dependent
member types.

Fixes rdar://problem/32697033.
2017-07-11 13:03:16 -07:00
Alex Hoppen
f35f29d9cf [Diag] Change function diagnostics to take a DeclName parameter
This provides richer error messages that include the function's
parameters
2017-07-01 13:37:08 +02:00
Slava Pestov
76a005587b Sema: Specialization of nested types in expression context
Teach preCheckExpression() about UnresolvedSpecializeExpr
where the base is a TypeExpr.

This allows us to type check expressions like
'[Outer<T>.Inner<U>]()' by folding them down to a TypeExpr
with an array type.
2017-05-21 18:16:16 -07:00
Slava Pestov
b5721e8d8e AST: Remove AnyObject protocol 2017-05-02 19:45:00 -07:00
Max Moiseev
7d73b2e1ca Arithmetic => Numeric 2017-03-13 11:50:02 -07:00
Max Moiseev
835b8809d2 Merge branch 'master' into new-integer-protocols 2017-03-07 16:18:54 -08:00
Rintaro Ishizaki
af9d16b4d9 [QoI] Improve diagnostics for unbound generic types (#7178)
Since the type is declared in other modules, we should use Decl instead
of its location.
2017-02-07 15:26:13 +09:00
Max Moiseev
3522f3c47c Fixing tests with artihmetic operators back on concrete types 2017-01-23 14:56:29 -08:00