Commit Graph

1177 Commits

Author SHA1 Message Date
Mark Lacey
2793d06bdf [Constraint solver] Fix up CSDiag.cpp to use the type map.
Update CSDiag.cpp to use the constraint system's type map instead of
directly reading types from expressions.

As with past commits, the type map is not really enabled yet since we
still write types directly into expressions in the constraint solver.
2017-06-03 17:27:20 -07:00
Pavel Yaskevich
2d8dca0266 [QoI] Improve diagnostic for raw representable argument mismatch
Covers some common situations when switching from literal types e.g.
string or int to more Swift Way of raw representable enum of choices.

Resolves: rdar://problem/32431165, rdar://problem/31977537, rdar://problem/32432253
2017-06-02 18:22:23 -07:00
Pavel Yaskevich
c5f73c369f Merge pull request #10026 from xedin/rdar-32432145
[Diagnostics] Suggest removing anonymous closure parameters if none are expected
2017-06-01 00:17:55 -07:00
Pavel Yaskevich
b755960e82 [Diagnostics] Suggest removing anonymous closure parameters if none are expected
If the contextual closure type expects no parameters but N
parameters where used and all of the them are anonymous, let's
suggest removing them.

Resolves: rdar://problem/32432145
2017-05-31 23:59:34 -07:00
Pavel Yaskevich
c94fe94d5d [Diagnostics] Add a fix-it for optional to raw representable type conversion
Situations where there is a contextual RawRepresentable type is
used incorrectly would produce `<Type>(rawValue: )` fix-it only
in cases where neither or both sides of the expression are optional.
Let's fix that by adding a fix-it for optional to contextual raw
value type conversion.

Resolves: rdar://problem/32431736
2017-05-31 13:58:17 -07:00
Alex Hoppen
930ffdacff Remove implicit conversion from DeclBaseName to Identifier
This conversion just existed to aid migration from Identifier to
DeclBaseName and is no longer needed. It will technically not even be
correct once special names are introduced.
2017-05-31 16:02:00 +02:00
Alex Hoppen
ece660fad8 Remove getName from ValueDecl
Push the getName method from ValueDecl down to only those types that are
guaranteed to have a name that is backed by an identifier and that will
not be special.
2017-05-31 16:00:47 +02:00
Alex Hoppen
faa1720c48 [Diagnostics] Adjustments for DeclBaseName
Adjust the definition of some diagnostics that are already called with
DeclBaseNames so that the implicit conversion from DeclBaseName to
Identifier is no longer needed.

Adjust the call side of diagnostics which don't have to deal with
special names to pass an Identifier to the diagnostic.
2017-05-31 15:58:46 +02:00
Mark Lacey
12926eb667 [Constraint solver] More type map updates.
More updates to read and write types from a side table in the constraint
solver and only write back into expressions when we've finished type
checking an expression.

We still write directly into expressions, and will continue to do so
until all of the code has been updated.
2017-05-31 00:36:09 -07:00
Pavel Yaskevich
da4232e546 [Diagnostics] Fix checking for presence of type variables in closure return expression
Instead of validating sub-expressions included in the closure's result
`diagnoseAmbiguousMultiStatementClosure` was only checking parent expression
by mistake.
2017-05-30 02:42:56 -07:00
Jordan Rose
4468ad2028 [Sema] Preparations for removal of getName on ValueDecl (#9972)
With the introduction of special decl names, `Identifier getName()` on
`ValueDecl` will be removed and pushed down to nominal declarations
whose name is guaranteed not to be special. Prepare for this by calling
to `DeclBaseName getBaseName()` instead where appropriate.
2017-05-28 22:36:39 -07:00
Jordan Rose
c0ccdb1626 Change getBaseName to return DeclBaseName instead of Identifier (#9968)
This changes `getBaseName()` on `DeclName` to return a `DeclBaseName`
instead of an `Identifier`. All places that will continue to be
expecting an `Identifier` are changed to call `getBaseIdentifier` which
will later assert that the `DeclName` is actually backed by an
identifier and not a special name.

For transitional purposes, a conversion operator from `DeclBaseName` to
`Identifier` has been added that will be removed again once migration
to DeclBaseName has been completed in other parts of the compiler.

Unify approach to printing declaration names

Printing a declaration's name using `<<` and `getBaseName()` is be
independent of the return type of `getBaseName()` which will change in
the future from `Identifier` to `DeclBaseName`
2017-05-28 17:55:03 -07:00
Jacob Bandes-Storch
035179331b [CSDiag] Fix crasher in KeyPathExpr diagnosis (#9962)
New KeyPathExpr diagnosis recently added in #9845 did not work for Obj-C key paths.
2017-05-27 13:36:56 -07:00
Slava Pestov
586dda2eb3 Sema: Replace TVO_MustBeMaterializable with TVO_CanBindToInOut
The old TVO_MustBeMaterializable is now equivalent to
!TVO_CanBindToLValue && !TVO_CanBindToInOut.

I tried to update all usages of createTypeVariable() to
pass TVO_CanBindToInOut unless they explicitly passed
TVO_MustBeMaterializable before.

However, in reality TVO_CanBindToInOut is the rare case;
we can remove this flag gradually over time to fix
crashes and diagnostics.
2017-05-26 21:08:08 -07:00
Slava Pestov
1b254a9843 Sema: Kill off old modeling of generic arguments 2017-05-24 20:39:10 -07:00
Slava Pestov
b3a6b852fc Merge pull request #9870 from slavapestov/unbound-generic-type-cleanup
Sema: Refactoring unbound generic types in expression context
2017-05-23 12:57:34 -07:00
Slava Pestov
a6dfcd52cf Sema: Remove OverloadChoiceKind::TypeDecl, which was never used 2017-05-23 02:10:02 -07:00
Pavel Yaskevich
ab101eb4e8 Merge pull request #9839 from xedin/rdar-32330004
[QoI] Check before trying to emit fix-it to convert from array to dictionary
2017-05-22 22:02:05 -07:00
Pavel Yaskevich
794b8d08fa Merge pull request #9812 from xedin/rdar31977679
[QoI] Improve diagnostics for subscript with invalid index arguments
2017-05-22 18:15:03 -07:00
Pavel Yaskevich
0b0d8074ad [QoI] Check before trying to emit fix-it to convert from array to dictionary
Before trying to replace every other "," with ":" to help convert
from array to dictionary, let's first check if it's appropriate e.g.
the number of commas matches the number of elements and number of
elements in the array is even which constitutes key/value pairs.

Resolves: SR-4952.
2017-05-22 17:12:06 -07:00
swift-ci
ae984977e0 Merge pull request #9845 from xedin/rdar-32209039 2017-05-22 16:34:28 -07:00
Pavel Yaskevich
817798151a [QoI] Add a fix-it with missing parameters for closures
If there are parameters missing in the closure declaration and
all of the present ones are anonymous let's emit a fix it suggesting
missing parameters.

Resolves: rdar://problem/32301091
2017-05-22 15:10:41 -07:00
Pavel Yaskevich
6d160482e8 [QoI] Improve diagnostic when unsupported tuple element references are used in key path literals
Resolves: rdar://problem/32209039.
2017-05-22 14:53:02 -07:00
Joe Groff
879397008c Sema: Don't crash when recovering type errors from malformed keypath expressions.
It's particularly likely someone will try to type `\(foo)`, which looks like a string interpolation segment, outside of a string literal, so give that case a special diagnostic. Fixes rdar://problem/32315365.
2017-05-22 10:42:40 -07:00
Pavel Yaskevich
89c104b709 [QoI] Improve diagnostics for subscript with invalid index arguments
In `FailureDiagnosis::visitSubscriptExpr` if there is only a single
candidate available, verify that the problem is actually related
to the contextual mismatch by type-checking whole subscript without
contextual info, if that returns a type - it's contextual, otherwise
diagnose as incorrect argument type problem.

Resolves: rdar://problem/31977679
2017-05-21 21:56:43 -07:00
Pavel Yaskevich
dd9469e7a9 [QoI] Switch to diagnoseMemberFailures for unresolved members 2017-05-17 12:00:23 -07:00
Pavel Yaskevich
e0f0a418ab [QoI] Switch to diagnoseMemberFailures for subscripts 2017-05-17 12:00:23 -07:00
Pavel Yaskevich
573f20e55c [QoI] Unify member diagnostics into one FailureDiagnosis method 2017-05-17 12:00:23 -07:00
Pavel Yaskevich
9a07f28ac4 Merge pull request #9587 from xedin/rdar-31973368
[QoI] Extend single tuple parameter diagnostics to function/subscript calls
2017-05-15 21:29:42 -07:00
Pavel Yaskevich
ead1447aa1 [QoI] Extend single tuple parameter diagnostics to function/subscript calls
Properly diagnose cases of function/subscript argument tuple
structuring/destructuring related by not limited to SE-0110.

Resolves: rdar://problem/31973368
2017-05-15 18:41:41 -07:00
Pavel Yaskevich
7ad9cbee99 Merge pull request #9624 from xedin/rdar-32101765
[QoI] Improve diagnostics for Smart KeyPath
2017-05-15 16:51:44 -07:00
Pavel Yaskevich
8e8ead31d3 [QoI] Improve diagnostics for Smart KeyPath
Add `FailureDiagnostics::visitKeyPathExpr` to try and diagnose contextual
value type problems related to Smart KeyPath feature. If problems with
contextual value type can't be diagnosed let's walk components and see
if there are any structural problems with expression itself e.g. unknown
members and incorrect types in the path.

Resolves: rdar://problem/32101765
2017-05-15 14:43:37 -07:00
Ben Cohen
ea2f64cad2 [stdlib] Add Sequence.Element, change ExpressibleByArrayLiteral.Element to ArrayLiteralElement (#8990)
* Give Sequence a top-level Element, constrain Iterator to match

* Remove many instances of Iterator.

* Fixed various hard-coded tests

* XFAIL a few tests that need further investigation

* Change assoc type for arrayLiteralConvertible

* Mop up remaining "better expressed as a where clause" warnings

* Fix UnicodeDecoders prototype test

* Fix UIntBuffer

* Fix hard-coded Element identifier in CSDiag

* Fix up more tests

* Account for flatMap changes
2017-05-14 06:33:25 -07:00
David Farler
0c48f71384 Migrator/QoI: Function input type: Don't fix Void to (Void), but fix (Void) to ()
```swift
func foo(f: Void) -> ()) {}
```

This compiler currently suggests we change this to:

```swift
func foo(f: (Void) -> ()) {}
```

That's `(()) -> ()`, almost certainly not what someone wants in Swift
4. We should suggest changing that to:
```swift
func foo(f: () -> ()) {}
```

Additionally,

```swift
func foo(f: (Void) -> ()) {}
```

Should trigger a warning that the `(Void)` input type is `(())`, and you
can't supply `()` to it in Swift 4, and suggest a fix-it change it to:

```swift
func foo(f: () -> ()) {}
```

rdar://problem/32143617
2017-05-13 17:36:28 -07:00
Pavel Yaskevich
756136b286 Merge pull request #9497 from xedin/rdar-31898542
[QoI] Improve diagnostics for unresolved member with incorrect arguments
2017-05-11 11:52:33 -07:00
Pavel Yaskevich
c0bc4f20be [QoI] Improve diagnostics for unresolved member with incorrect arguments
`FailureDiagnosis::visitUnresolvedMemberExpr` tries to use the same logic
as `diagnoseSingleCandidateFailures` so instead of doing that let's remove
some of the special handling and use `diagnoseSingleCandidateFailures`
directly instead, which improves label diagnostics and handles more erroneous
cases as well.

Resolves: rdar://problem/31898542
2017-05-11 01:31:33 -07:00
swift-ci
e305259ef0 Merge pull request #9384 from xedin/rdar-31724211 2017-05-11 00:37:15 -07:00
Pavel Yaskevich
ddaccf88bb [QoI] Properly diagnose closure parameter distructuring after SE-0110
Swift 3 supported limited argument destructuring when it comes to
declaring (trailing) closures. Such behavior has been changed by
SE-0110. This patch aims to provide better error message as well
as fix-it (if structure of the expected and actual arguments matches)
to make the migration easier and disambiguate some of the common
mistakes.

Resolves: SR-4738, SR-4745, rdar://problem/31892961.
2017-05-08 23:04:37 -07:00
Pavel Yaskevich
c72b402afa [QoI] Improve diagnostics for generic subscripts
While diagnosing index expression associated with subscript call
`validateContextualType` didn't look through TupleType to identify
potential nullability of the contextual type related to generic
parameters.

Resolves: rdar://problem/31724211
2017-05-08 02:41:02 -07:00
Pavel Yaskevich
5adeff065c [QoI] Improve diagnostics for calling instance methods on type or in static context.
Previously situations like `self.foo(...)` wouldn't be considered as viable
for diagnosing the instance method on type calls, because the base wasn't
TypeExpr, which only accounts for e.g. `X.foo`, instead of validating base
expression itself this patch checks if the _type_ of base expression is
Metatype which is less restrictive.

Resolves: SR-4692.
2017-05-07 01:29:50 -07:00
Slava Pestov
dd7b62c0d8 Sema: Fix crash with ambiguous overload inside a trailing closure
Any ambiguity inside of a call with a trailing closure
call was going down the code path that would tell you to
add an argument label... but the ambiguity might not be
with the call that has the trailing closure itself, and
instead something inside.
2017-05-05 23:54:22 -07:00
Michael Gottesman
86620aaa7e Merge pull request #9318 from practicalswift/redundant-types-in-casts
[gardening] Remove redundant repetition of type names (DRY): RepeatedTypeName foo = dyn_cast<RepeatedTypeName>(bar)
2017-05-05 13:37:12 -07:00
practicalswift
492f5cd35a [gardening] Remove redundant repetition of type names (DRY): RepeatedTypeName foo = dyn_cast<RepeatedTypeName>(bar)
Replace `NameOfType foo = dyn_cast<NameOfType>(bar)` with DRY version `auto foo = dyn_cast<NameOfType>(bar)`.

The DRY auto version is by far the dominant form already used in the repo, so this PR merely brings the exceptional cases (redundant repetition form) in line with the dominant form (auto form).

See the [C++ Core Guidelines](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#es11-use-auto-to-avoid-redundant-repetition-of-type-names) for a general discussion on why to use `auto` to avoid redundant repetition of type names.
2017-05-05 09:45:53 +02:00
David Farler
be86bcac1d [Migrator] Suggest String <-> Substring conversions
Some APIs that expected a String now expect a Substring and vice
versa. To ease the transition, emit fix-its on conversion errors
between these types that the migrator can pick up.

When converting from Substring -> String, suggest wrapping in
`String.init`.

When converting from String -> Substring, suggest appending the
void subscript `[]`. (This isn't implemented yet so this is
hidden behind a flag).

This can possibly be generalized later when converting between
some sequence and its subsequence, such as Array and ArraySlice,
for example.

rdar://problem/31665649
rdar://problem/31666638
2017-05-04 16:40:56 -07:00
Slava Pestov
b5721e8d8e AST: Remove AnyObject protocol 2017-05-02 19:45:00 -07:00
Robert Widmann
253d0080ef Improve diagnostic for attempted initialization of non-nominal types 2017-04-29 20:29:20 -04:00
practicalswift
4ef5c6d840 [gardening] Remove unused variables 2017-04-25 21:03:41 +02:00
Joe Groff
595e0e4ede Merge branch 'master' into keypaths 2017-04-19 18:38:24 -07:00
practicalswift
5e255e07d7 [gardening] Remove redundant logic 2017-04-11 23:04:55 +02:00
Joe Groff
964dc0e174 Sema: (wip) Overload resolution for keypath subscripts.
TODO: Some diagnostic regressions:
test-macosx-x86_64/Compatibility/tuple_arguments.swift
test-macosx-x86_64/Constraints/diagnostics.swift
test-macosx-x86_64/Constraints/tuple_arguments.swift
test-macosx-x86_64/expr/unary/keypath/keypath.swift
test-macosx-x86_64/expr/unary/selector/selector.swift
2017-04-09 16:38:02 -07:00