Commit Graph

1357 Commits

Author SHA1 Message Date
Pavel Yaskevich
c45073efd1 [QoI] Don't try to lookup members on incorrect type while diagnosing keypath components
While trying to diagnose problems related to keypath components
don't assume that type of the component is always correct, check
before trying to see if it's bridged type or has members.

Resolves: rdar://problem/33135487
2017-07-05 17:19:05 -07:00
David Rönnqvist
00833a2343 [QoI] Improve the fix-it for out-of-order arguments.
Change the fix-it to move the argument to its correct location in one go. This happens by removing it from one location and inserting it in the other (as opposed to the original implementation which swapped one argument with the preceding one). The commas separating the arguments are adjusted to match the moved argument.

Add new tests for reordering regular arguments, variadic arguments, and function arguments.

Resolves: SR-4715 rdar://problem/31849281
2017-07-02 10:15:18 +02: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
Pavel Yaskevich
a82b16fb2d [QoI] Don't assume that contextual type is always present for trailing closure diagnostics
Fixes crasher in diagnostics related to the fact that contextual type
is not always available when trying to diagnose problems related to
calls with trailing closures.

Resolves: rdar://problem/33067102
2017-06-29 23:09:55 -07:00
practicalswift
d39719ec3f [gardening] Fix typos 2017-06-29 23:09:22 +02:00
Pavel Yaskevich
ef55d42334 [QoI] Emit shadowing diagnostics even if argument types do not much completely
Relax restriction placed on the function shadowing diagnostics
and allow such diagnostics to be emitted even when argument types
do not match expected parameter types, but use "near match" message
in that case to clarify that shadowing is not exact.

Resolves: rdar://problem/32854314
2017-06-28 13:35:26 -07:00
Pavel Yaskevich
1ffac2e651 [QoI] Improve diagnostics related to member calls
When trying to diagnose problems related to calls where
function is represented by a member of nominal type let's
attempt to be more cautious while type-checking function
expression without it's arguments, because it could produce
unrelated diagnostics.

Resolves: rdar://problem/32551313, rdar://problem/28456467, rdar://problem/31671195
2017-06-27 15:49:11 -07:00
swift-ci
f9b2047cc0 Merge pull request #10571 from xedin/sr-5045 2017-06-26 14:08:42 -07:00
Pavel Yaskevich
4e6677e7c4 [QoI] Improve contextual error diagnostics related to calls
Currently some contextual errors are discovered too late
which leads to diagnostics of unrelated problems like argument
mismatches, these changes attempt to improve the situation
and try to diagnose contextual errors related to calls
before everything else.

Resolves: SR-5045, rdar://problem/32934129
2017-06-26 13:12:32 -07:00
Alex Hoppen
949968a182 Adjust printing to take into account special DeclNames
Print DeclBaseNames using a new userFacingStr() method to prepare for
DeclBaseNames that are not backed by Identifiers
2017-06-24 11:39:09 +02:00
Huon Wilson
18078c104e Merge pull request #10476 from huonw/cleanups
Small clean-ups
2017-06-22 14:30:46 -07:00
Huon Wilson
77781b8754 [NFC] Use std::tuple instead of hand-written lexicographical comparison. 2017-06-22 12:48:55 -07:00
Robert Widmann
da35f11486 Merge pull request #10453 from CodaFi/high-and-DRY
Unify CallArgParam and AnyFunctionType::Param
2017-06-21 14:11:26 -07:00
Pavel Yaskevich
676a48ff4f [QoI] Adapt new diagnostics to reverted portion of SE-0110 and new function input decomposition 2017-06-21 12:29:29 -07:00
Robert Widmann
0795c9946c Unify CallArgParam and AnyFunctionType::Param 2017-06-21 11:31:51 -07:00
Pavel Yaskevich
2fd247a833 [QoI] Improve contextual mismatch diagnostics in calls with trailing closures
Resolves: rdar://problem/28012273
2017-06-21 11:27:35 -07:00
Pavel Yaskevich
2c7c74390d [QoI] Ignore incorrect parameter types when trying to diagnose trailing closures
Resolves: rdar://problem/28004686
2017-06-21 11:27:12 -07:00
Pavel Yaskevich
a5960d8993 [Diagnostics] NFC: Refactor closure result type validation into a function 2017-06-21 11:27:12 -07:00
Pavel Yaskevich
3a77295835 [QoI] Use information known about call parameters via failed constraint
This makes it a lot easier to diagnose contextual mismatch related
to arguments used by the call without relying on the type of the
function expression which is not always available.
2017-06-21 11:27:12 -07:00
Pavel Yaskevich
c46e3e83e8 [QoI] Improve diagnostics for single argument calls with trailing closures
Calls involving single trailing closure arguments require special
handling because we don't have as much contextual information
about function/argument types as in with regular calls, which means
that diagnosing such situations only by `visitApplyExpr`
yields subpar results.

Resolves: SR-4836.
2017-06-21 11:26:38 -07:00
Robert Widmann
9fa8341540 Only decompose function types for info about default arguments
AnyFunctionType::Param carries around information about decomposed
parameters now.  Information about default arguments must be computed
separately with swift::computeDefaultMap.
2017-06-19 23:05:44 -07:00
Alex Hoppen
6f3b8ca60f Merge pull request #9978 from ahoppen/pdm-remove-implicit-conversion
Remove implicit conversion from DeclBaseName to Identifier
2017-06-17 16:02:51 +02:00
Alex Hoppen
5cda94b1c1 Merge pull request #9977 from ahoppen/pdm-remove-get-name
Remove getName method from ValueDecl
2017-06-17 12:07:21 +02:00
Slava Pestov
a6339be1cd Sema: Fix historical quirk with @escaping diagnostics
Saying "implicitly non-escaping because it was declared @autoclosure"
does not make sense. Since Swift 3, parameters of function type are
non-escaping by default, whether or not they are @autoclosure.

We would also inhibit the fixit for inserting @escaping if the
@autoclosure attribute was present. Again, a holdover from the
Swift 2 days, when @autoclosure implied @noescape and the special
@autoclosure(escaping) attribute was used to define an escaping
autoclosure.
2017-06-17 00:48:07 -07:00
Alex Hoppen
2078ec6f0a 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-06-15 21:49:34 +02:00
Robert Widmann
abd5aa8e6d Rename some X-Value-related entities
* Rename coerceToMaterializableValue to coerceToRValue

* Rename isLValueType to hasLValueType to better match the
intended semantics of the member.
2017-06-14 13:18:45 -07:00
Alex Hoppen
d922944af0 Merge pull request #9976 from ahoppen/pdm-diagnostics2
Migration to DeclBaseName in diagnostic definitions
2017-06-13 12:55:16 +02:00
Robert Widmann
3b26466cef Clean up some UB
* The SILBuilder could potentially reference itself during its own
initialization if a valid insertion point was left around and a
new basic block was created.  Move basic block creation after the
initializer instead.

* CSDiag was comparing canonical types for equality directly, which
leads to mixed-type comparisons if one side of the comparison is nullptr.
Use isEqual instead.
2017-06-08 16:47:48 -07:00
Alex Hoppen
e7da52776c Merge pull request #10152 from ahoppen/fixit-optional-switch
[Diag] Correct fixit location of "?" when pattern matching optional with non-optional
2017-06-07 10:59:54 -07:00
Alex Hoppen
99acf816f4 [Diag] Correct fixit location of "?" when pattern matching optional with non-optional
Trying to pattern match an optional with a non-optional should provide
a fixit inserting a "?" after the last token and not before it.
2017-06-07 07:25:46 -07:00
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