Commit Graph

52 Commits

Author SHA1 Message Date
Doug Gregor
a1af0e45cb [Constraint solver] Reject trailing closures matching non-closure-parameters.
Enhance call-argument matching to reject trailing closures that match up
with parameters that cannot accept closures at all.

Fixes rdar://problem/50362170.
2019-04-30 23:12:32 -07:00
Slava Pestov
91dffc9d44 Sema: Use AnyFunctionType::printParams() to print argument lists instead of printing a tuple type
Once the '@escaping' bit is removed from TupleTypeElt, it no longer makes
sense to print argument lists as if they were TupleTypes or ParenTypes,
since function types are '@escaping' by default inside tuples but not
in argument lists.

Instead, print ArrayRef<AnyFunctionType::Param> directly. For now this
introduces some awkward usages of AnyFunctionType::decomposeInput();
these will go away once the AST is changed to represent the argument list
as a list of expressions and not a single tuple expression.
2019-04-15 00:22:29 -04:00
Pavel Yaskevich
688042becf [Diagnostics] Add inaccessible member diagnostic 2019-03-18 13:48:08 -07:00
Pavel Yaskevich
5dd5454a75 [CSSimplify] Determine if argument is out-of-order while matching labels
Instead of rerouting out-of-order into re-labeling during diagnostics,
let's do that as part of the label matching algorithm.
2019-03-04 20:03:30 -08:00
Joe Groff
89979137fc Push ArchetypeType's API down to subclasses.
And clean up code that conditionally works only with certain kinds of archetype along the way.
2018-12-12 19:45:40 -08: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
Adrian Prantl
ff63eaea6f Remove \brief commands from doxygen comments.
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.

Patch produced by

      for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
2018-12-04 15:45:04 -08:00
Pavel Yaskevich
c219af099e [Diagnostics] NFC: Rename OverloadCandidate::getUncurried{Function}Type -> OverloadCandidate::get{Function}Type 2018-10-19 14:56:06 -07:00
Pavel Yaskevich
a0085e1f29 [Diagnostics] NFC: Rename UncurriedCandidate -> OverloadCandidate 2018-10-19 13:37:05 -07:00
Pavel Yaskevich
1265f2e81e [Diagnostics] Replace curry level with a boolean flag
Since arbitrary currying is no longer allowed `level` could
be replaced with the boolean flag which identifies if curried
`self` should be skipped or not.
2018-10-18 15:14:13 -07:00
Pavel Yaskevich
efd2069f0c [CSDiag] Don't increase candidate curry level if base is ignored
When `CandidateCalleeInfo` tries to create a candidate for expression
in form of `<base>.<func>` it shouldn't assume that function type of
'<func>' would always be at curry level 1, because base could be ignored
when it is a module or 'b' refers to a static function.

Resolves: rdar://problem/45242032
2018-10-17 17:47:42 -07:00
Slava Pestov
3b60ae153d AST: Rename AnyFunctionType::Param::getType() to getOldType() 2018-09-26 11:05:23 -07:00
Michael Gottesman
c62f31f5dc Inject llvm::SmallBitVector into namespace swift;
I also eliminated all llvm:: before SmallBitVector in the code base.
2018-09-21 09:49:25 -07:00
Slava Pestov
c68cbe85ec Sema: Remove hasAccess() checks 2018-09-05 16:50:41 -07:00
Slava Pestov
527ff375dc AST: Rename old form of {Generic,}FunctionType::get() to getOld()
This makes it easier to grep for and eventually remove the
remaining usages.

It also allows you to write FunctionType::get({}, ...) to call the
ArrayRef overload empty parameter list, instead of picking the Type
overload and calling it with an empty Type() value.

While I"m at it, in a few places instead of renaming just clean up
usages where it was completely mechanical to do so.
2018-08-17 19:28:17 -04:00
Slava Pestov
1bbea4af55 AST: Clean up AnyFunctionType::Param API a bit 2018-08-17 19:26:40 -04:00
gregomni
4d862d50cb In tryTypeVariableBindings, if T? fails, try T for all binding kinds (previously just allowed for Subtypes). This allows us to always find MissingOptionalUnwrapFailures, so that all the unwrap fixit code can be moved into CSDiagnostics and made static. 2018-08-14 09:14:59 -07:00
Greg Titus
8f41ee7750 Merge pull request #18324 from gregomni/opty2
[Sema] More unwrap fixits
2018-08-14 09:12:35 -07:00
Doug Gregor
6384d080b1 Merge pull request #18539 from DougGregor/unqualified-lookup-via-decls
[Name lookup] Use decl-based name lookup more regularly
2018-08-14 05:18:59 -04:00
Doug Gregor
713c92d81b [Type checker diags] Validate constructors when they don’t have interface types.
Fixes a diagnostics regression due to the name-shadowing changes.
2018-08-13 22:31:09 -07:00
Slava Pestov
31a570d53c AST: Replace TypeBase::getRValueInstanceType() with getMetatypeInstanceType()
That is, don't look through InOutType anymore, and update callers to
call getInOutObjectType() as well (or not, where it was obvious to me
that InOutType could not appear).

This surfaces more remaining uses of getInOutObjectType() directly.
2018-08-13 21:13:10 -07:00
gregomni
36cf24fb9e When we diagnose an unwrap, if the expression being unwrapped is a sole reference to a local let/var, and the local's type is inferred, offer fixits on the initializer as well. In this position we can also reasonably offer 'guard let'. Since we're identifying the implicitly typed initializer now, we can give a specific explanation of how IUOs get turned into optional types with the new IUO implementation.
Pass constraint system down into offering force unwrap fixits so that we can identify the type of the last member chosen for an optional chain. If there's a chain and the last member's return type isn't optional, then it's cleaner to offer to change that last '?' into a '!' to perform the force, rather than parenthesize the whole expression and force the result.
2018-08-12 12:57:20 -07:00
Pavel Yaskevich
0a404529c3 [Sema] Adjust Diagnostics/IDE to not assume that parameters always have types 2018-07-28 20:28:41 -07:00
Doug Gregor
5c008ab2ce [Type checker] Don't substitute into unresolved types.
Unresolved types are formed in a few specific places within the type
checker's recovery path; don't let them bleed into the substitution
logic. Fixes rdar://problem/42448618.
2018-07-24 16:56:43 -07:00
Pavel Yaskevich
41917d9f49 Merge pull request #18148 from xedin/match-call-arguments-imporovements
[TypeChecker] Improve argument label matching
2018-07-23 15:32:09 -07:00
Slava Pestov
90cd772228 AST: Remove getParameterLists() and friends from AbstractFunctionDecl subclasses
Now, an AbstractFunctionDecl always stores a single parameter list.

Furthermore, ConstructorDecl and DestructorDecl always store a
ParamDecl for 'self'.

FuncDecl only has a 'self' if it is a member of a nominal type or
extension, so we tail-allocate the storage for it.
2018-07-22 20:56:56 -07:00
Slava Pestov
b203e2fb1a Sema: Hack up CSDiag for removal of multiple parameter lists 2018-07-22 20:56:56 -07:00
Pavel Yaskevich
91e330c289 [TypeChecker] Improve argument label matching
* Improve label mismatch callback:
 - Split "missing label" callback into 3 - missing, extraneous, incorrect (with typo(s));
 - Allow label callbacks to indicate if it's a fatal error or not;
* Improve matching of the variadic parameters;
* Improve matching of the parameters with defaults;
* Try to look for an argument with matching label before fallback to
  forced claming (if allowed).
2018-07-21 23:21:42 -07:00
Doug Gregor
5db1901d57 [Type checker] Emit coalesce-or-force-unwrap Fix-Its for necessary unwraps more consistently.
Replace the last (and most obscure) use of the poor “use ‘?’ or ‘!’” diagnostic with the
new, more explanatory version that provides separate notes with Fix-Its for coalescing or
force-unwrapping the value.

Finishes rdar://problem/42081852.
2018-07-13 16:48:15 -07:00
Ding Ye
95b91ee953 Apply git-clang-format. 2018-07-11 15:26:56 +10:00
Ding Ye
e884126acd Improve comment phrasing 2018-07-11 15:26:56 +10:00
Ding Ye
c4c730f8d1 [Sema] Diagnostic: improve diagnostics for ApplyExpr.
When diagnosing ApplyExpr, the existing implementation
tries to resolve the function subexpression independently
in the first place, without considering the argument
information. As a result, such resolved function type
may not produce the best diagnostic message.
This patch adds condideration of the number of arguments
to decide the better function subexpression for diagnostic
purpose.

Resolves: SR-7918, SR-7786, SR-7440, SR-7295, SR-5154.
2018-07-11 15:26:55 +10:00
Doug Gregor
80688d0176 [Type Checker] Remove the TypeChecker from most of the “override” checking.
A type checker instance isn’t needed for most of the “override” checking,
so remove the TypeChecker parameters and instead get the ASTContext or
DiagnosticEngine from whatever decl or type is available. Another step
toward reducing dependency on a TypeChecker instance.
2018-07-02 23:00:39 -07:00
Robert Widmann
24abf3ea09 [NFC] Refactor default argument info
Refactor the interface to return a bit vector. Along the way, fix up
the callers and remove some dead usages of the defaults information
that were copied and pasted around Sema.
2018-05-31 17:28:04 -07:00
Anthony Latsis
7139152132 [Diagnostics|SR-5789] Fixits for applying subscripts by keyword (#16431)
* [Diagnostics|SR-5789] Added fixits for referring to subscripts by keyword

If there is a subscript member, the error message changes to [type -bash has no member property or method named 'subscript']
The fix-it replaces parentheses with brackets, removes '.subscript'
If the apply expression is incomplete, e.g. subscript(..., the fix-it adds a bracket at the end.

* tests updated & logic for compatible arg types (except generics)

* ignore generic types & switch to returning

* avoid explicitly using sting literals

* handle implicit conversion of tuples & encapsulate it

* isolate subscript misusage

* return bool instead of void

* move function to FailureDiagnosis, diagnose independently & update error message

* Update CSDiag.cpp
2018-05-22 11:18:27 -07:00
Doug Gregor
049c56dde6 Eliminate getForwardingSubstitutions().
Use the SubstitutionMap version everywhere.
2018-05-11 17:37:27 -07:00
Slava Pestov
7a98297e79 Sema: Fix crash when diagnosing failed dynamic lookup of 'init'
Fixes <rdar://problem/39818322>.
2018-05-04 23:36:50 -04:00
Pavel Yaskevich
3c64680a91 [Diagnostics] Switch CalleeCandidateInfo to use FunctionType::getParams() 2018-04-26 17:33:08 -07:00
Pavel Yaskevich
57ad592844 [Sema] Switch computeDefaultMap to use AnyFunctionType::getParams() 2018-04-26 17:33:08 -07:00
Robert Widmann
03580d2fe5 Add a parameter list to EnumElementDecl
This models, but does not plumb through, default arguments.
2018-03-28 00:05:56 -04:00
Slava Pestov
e0def7b01f Sema: Move TypeChecker::isSubstitutableFor() to CalleeCandidateInfo 2018-03-23 20:14:11 -07:00
Slava Pestov
34fd4ae512 AST: Use DeclBaseName::Kind::Constructor
Fixes <rdar://problem/35852727>, <https://bugs.swift.org/browse/SR-1660>,
<https://bugs.swift.org/browse/SR-6557>.
2018-03-16 00:25:56 -07:00
Slava Pestov
615d068d63 Sema: Replace some uses of getBaseIdentifier() with userFacingName() 2018-03-14 22:26:58 -07:00
Mark Lacey
b4b66bc8e8 Replace getAnyOptionalObjectType with getOptionalObjectType. 2018-02-05 23:59:00 -08:00
Mark Lacey
3654dcc8fe Remove getImplicitlyUnwrappedOptionalObjectType. 2018-02-03 10:57:11 -08:00
Mark Lacey
ad1dbac694 IUO: Create disjunctions for optional choices.
When binding an optional value, or function that returns an optional
value, if that value was produced from a decl that was declared an
IUO, create a disjunction.

After solving, make use of the disjunction choices in rewriting
expressions to force optionals where needed.

This is disabled for now, as it results in a source compatibility
issue without associated changes that actually start generating
Optional<T> in place of ImplicitlyUnwrappedOptional<T>. It's
complicated, but basically having two '??' (one returning T, one
returning T?) and creating a disjunction where the first (favored)
choice is ImplicitlyUnwrappedOptional<T> and second is T results in
our selecting the wrong '??' in some cases.
2018-01-08 14:31:03 -08:00
Mark Lacey
41479f6334 IUO: Start creating the DeclForImplicitlyUnwrappedOptional OverloadChoice.
Use this in places where we have a decl that is marked with the
ImplicitlyUnwrappedOptionalAttr so that we can distinguish in the
solver which decls need to be potentially unwrapped in order to type
check successfully.
2018-01-04 14:00:36 -08:00
Slava Pestov
50fa92c8a7 Merge pull request #12567 from gregomni/diagnosis
[Sema] Better ambiguity diagnosis in overloaded function calls
2017-10-22 22:49:39 -07:00
gregomni
345c4a933d Save unresolved arg number from callee candidate info, use it to diagnose ambiguity sooner and
more specifically.
2017-10-22 10:32:11 -07:00
Robert Widmann
ebdd126a2c [NFC] Remove more uses of <InOutType> 2017-10-22 02:00:07 -04:00