Commit Graph

53 Commits

Author SHA1 Message Date
Ben Langmuir
d59a57339e [CodeCompletion] Add some basic sanity tests for generic typealiases
Basically check that the name of the type shows up as a result, and that
we can look through to the members of the underlying type.
2016-03-08 20:13:16 -08:00
Ben Langmuir
8f9299cc97 [CodeCompletion] Add assignment to experimental operator completion
When the LHS is an lvalue/assignable tuple and there is no leading
sequence of binary expressions.

It's a bit hacky right now since we don't have a good way to
differentiate general pattern completions from builtin operators.

rdar://problem/23209683
2016-03-02 18:21:37 -08:00
Daniel Duan
780b58a9a5 [Parser] update tests for 'inout' syntax adjustment 2016-02-26 01:33:22 -08:00
David Farler
3f635d04c7 Reinstante var bindings in refutable patterns, except function parameters.
This reverts commits: b96e06da44,
                      8f2fbdc93a,
                      93b6962478,
                      64024118f4,
                      a759ca9141,
                      3434f9642b,
                      9f33429891,
                      47c043e8a6.

This commit leaves 'var' on function parameters as a warning to be
merged into Swift 2.2. For Swift 3, this will be an error, to be
converted in a follow-up.
2016-01-29 15:27:08 -08:00
Doug Gregor
38c1de69e4 Reinstate "[SR-511][Parse] Add 'associatedtype' keyword and fixit"
This reverts commit ce7b2bcf09, tweaking
a few validation tests appropriately (1 crasher fixed, two -verify
tests that needed updating).
2016-01-14 00:21:48 -08:00
Erik Eckstein
ce7b2bcf09 Revert "[SR-511][Parse] Add 'associatedtype' keyword and fixit"
This reverts commit 2b2e9dc80e.

It broke some compiler crasher tests
2016-01-13 20:42:58 -08:00
gregomni
2b2e9dc80e [SR-511][Parse] Add 'associatedtype' keyword and fixit
Adds an associatedtype keyword to the parser tokens, and accepts either
typealias or associatedtype to create an AssociatedTypeDecl, warning
that the former is deprecated. The ASTPrinter now emits associatedtype
for AssociatedTypeDecls.

Separated AssociatedType from TypeAlias as two different kinds of
CodeCompletionDeclKinds. This part probably doesn’t turn out to be
absolutely necessary currently, but it is nice cleanup from formerly
specifically glomming the two together.

And then many, many changes to tests. The actual new tests for the fixits
is at the end of Generics/associated_types.swift.
2016-01-13 17:54:31 -08:00
Chris Lattner
5ce3de8dd6 remove & dial back three old bits of syntax auto-upgrading support:
1. Array type parsing for postfix array types Int[].  We now handle this
   in the parser, but remove the AST representation of this old form.  We
   also stop making vague promises about the future by saying that "fixed
   size arrays aren't supported... yet".  Removal of this fixes a compiler
   crasher too.

2. Remove the special case support for migrating @autoclosure from types
   to parameters, which was Swift 1.0/1.1 syntax.  The world has moved or
   we don't care anymore.

3. Remove upgrade support for # arguments (nee "backtick" arguments), which
   was a Swift 1.x'ism abolished in an effort to simplify method naming
   rules.

NFC on valid code.
2015-12-31 22:29:39 -08:00
ken0nek
fcd8fcee91 Convert [Cc]an not -> [Cc]annot 2015-12-23 00:55:48 +09:00
Daniel Duan
ebb0c3a204 replaced single-line ++/-- with +=/-= 2015-12-15 09:05:37 -08:00
Nick van der Ploeg
42b4b02df3 Fixed typos in comments throughout the project. 2015-12-07 12:15:52 -06:00
David Farler
8f2fbdc93a Make function parameters and refutable patterns always immutable
All refutable patterns and function parameters marked with 'var'
is now an error.

- Using explicit 'let' keyword on function parameters causes a warning.
- Don't suggest making function parameters mutable
- Remove uses in the standard library
- Update tests

rdar://problem/23378003
2015-11-09 16:56:13 -08:00
Ben Langmuir
7fda8964db [CodeCompletion] Add several more literal completions
Go beyond the existing keyword completions to include more literal
suggestions: 0, 0.0, "text", [item], [key: value], (item, item)

For rdar://problem/21923069

Swift SVN r32890
2015-10-26 20:41:56 +00:00
Ben Langmuir
a2c7298af5 [CodeCompletion] Don't complete entire call patterns inside existing calls
Peek at the token following the code completion location to decide
whether or not to provide completions for entire call patterns.  When
the next token looks like it's part of an existing call we don't show
the patterns because they will "push out" the existing arguments.

We should now get:
  Foo<here> =>  (blah, blah)
  Foo(<here> =>  ['(']blah, blah)
  Foo(<here>) => ['(']blah, blah[')']
  Foo(<here>, blah) => just complete the values for arg1**
  Foo(<here>blah, blah) => just complete the values for arg1

** A further improvement will be to add the argument label completion
for the first argument (if applicable) when we aren't showing a full
call pattern.

rdar://problem/22804670

Swift SVN r32765
2015-10-19 21:47:01 +00:00
Ben Langmuir
9448df6fae [CodeCompletion] Add initial support for completing infix operators
This allows us to start code-completing infix operators in postfix
expressions.  As a first step, this patch only handles completing
against the immediate LHS (so for example 1 == 1 <here> doesn't suggest
boolean operators yet).

The next step is to feed the leading sequence expression from the parser
in so we can consider how the operator being completed fits into the
whole sequence expression.

For rdar://problem/22460167

Swift SVN r32465
2015-10-06 20:48:03 +00:00
Doug Gregor
6af6048c0c AST printing: take more care to only escape 'Self' when needed.
Cleans up AST printing somewhat as well as providing slightly better
type-to-declaration mappings for annotated AST printing and indexing.

Swift SVN r32420
2015-10-03 05:13:52 +00:00
Xi Ge
c73a4e1509 [CodeComplete] Teach type context analyzer to analyzer for each statement. rdar://22831848
When completing at the sequence position of for each statment (for i in <HRER> {}),
values of sequence type should have higher priority than the rest.

Swift SVN r32202
2015-09-24 17:47:20 +00:00
Xi Ge
07a848cf64 [CodeComplete] Address Argyrios' review comments.
Swift SVN r31653
2015-09-03 02:36:11 +00:00
Xi Ge
08eda102ed [CodeComplete] Finish transforming archetypes to actual types in code completion results and update tests.
Swift SVN r31635
2015-09-02 20:18:16 +00:00
Ben Langmuir
f6f3becf6f [CodeCompletion] Remove duplicate results from protocol extensions
This fixes cases like [0].map and [].count having duplicate results.

rdar://problem/21106611

Swift SVN r30848
2015-07-31 05:00:26 +00:00
Xi Ge
5a1946eb53 [CodeCompletion] Add init() to the code completion results after metatype + dot.
rdar://21474100

Swift SVN r30781
2015-07-30 00:10:43 +00:00
Chris Lattner
7e5282ce6c reapply part of r29978, wherein we simplify CleanupIllFormedExpression,
and stop it from nuking types on decls inside of closures, which needlessly
pessimizes some IDE tests.



Swift SVN r29979
2015-07-08 18:18:46 +00:00
Chris Lattner
31facf7204 revert r29932, which is triggering a problem on the ASAN bot that I need to investigate.
Swift SVN r29978
2015-07-08 17:14:43 +00:00
Chris Lattner
e8877e9555 Several changes:
- Fix a diagnostic to not include redundant ''s around a type name.
 - Rework CleanupIllFormedExpression to be simpler and to not 
   unconditionally destroy data when it doesn't.  This makes a code 
   completion test a bit more precise.
 - Completely revamp getTypeOfIndependentSubExpression, to return the 
   subexpression produced by type checking instead of just a type.  This
   is important for cases when type checking changes the root of the AST
   (e.g. resolving an unresolved_dot_expr) and allows us to eliminate
   grungy and unsafe recovery code that was in place to work around this.

The last point makes the examples in Constraints/lvalues.swift better (giving
a somewhat generic error instead of an specific-but-incorrect error that 'z'
is immutable), but more importantly, it fixes a class of crashers like
<rdar://problem/21369926> Malformed Swift Enums crash playground service

where we'd end up with a LiteralExpr typed as Int instead of a Builtin integer
type of some sort.



Swift SVN r29932
2015-07-07 04:35:31 +00:00
Ben Langmuir
1be2a778c1 [CodeCompletion] Avoid choking on a doubly-typechecked expr
First, fix a case of type checking an expression twice, which is against
the design of the type checker. We hit this because we can type check
the "context" in
  let x = foo.#^COMPLETE^#
and then type check the "parsed expression", which is contained in the
context here.

Second, make the hack from rdar://20738314 more robust so that if we
*do* double typecheck for some reason we won't just choke on an
AutoClosureExpr.  I filed rdar://21466394 to audit for other cases of
double typechecking and remove this hack.

Fixes rdar://21346928

Swift SVN r29527
2015-06-19 22:16:07 +00:00
Ben Langmuir
7fcd0eeae5 [CodeCompletion] Add 'throws' and 'rethrows' to call descriptions
Completions for calling functions will now show 'throws' in the
description text so that users can differentiate throwing and
non-throwing calls. We don't insert this into the source text, since
it's not part of the call syntax.

rdar://problem/20978869

Swift SVN r28791
2015-05-19 21:46:20 +00:00
Ben Langmuir
0fbbe1807b [CodeCompletion] Fix crash completing method with associated type
protocol P { typealias T; func foo() -> T }
    func invalid(x: P) { x.#^COMPLETE^#

We were trying to access a null Type created because the associated type
doesn't make sense in the protocol type P (we can only use P as a
generic constraint, but it shouldn't crash code completion if we use it
incorrectly).

For rdar://problem/20305938

Swift SVN r28588
2015-05-14 22:46:59 +00:00
Ben Langmuir
69fdca43da Fix assertion failure code completing after nil literal
We were asserting (and doing the wrong thing) when trying to code
complete
    nil #^HERE^#

The issue is that we tried to apply a solution to the expression that
contained free type variables (converted to generic parameters). This
trips us up when we expect the new type to conform to protocols. In code
completion we generally only need the type of the expression, so this
commit switches to getting that more explicitly.  That said, this did
cause us to drop non-API parameter names in call patterns after an
opening '(' in some cases (covered by rdar://20962472).

Thanks to Doug for suggesting this solution!

rdar://problem/20891867

Swift SVN r28584
2015-05-14 22:22:37 +00:00
Ben Langmuir
163f47eab7 Complete protocol extension methods inside extension
After this change,
extension P where WHERE1 { final func foo() {} }
extension P where WHERE2 { final func bar() { #^COMPLETE_HERE^#

will complete foo() if and only if WHERE2 is complatible with WHERE1.

Swift SVN r27480
2015-04-20 16:20:40 +00:00
Ben Langmuir
8078a7b2d1 Remove unnecessary FIXMEs from previous commit
One was just a marker for myself; the other disabled a test that wasn't
passing at some point, but was at the point I committed.

Swift SVN r27445
2015-04-17 23:32:49 +00:00
Ben Langmuir
48cce21bdc Filter out completions from unusable protocol extensions
... and add a bunch more tests. Thanks to Doug for help with the
typechecker bits!

rdar://problem/20305938

Swift SVN r27444
2015-04-17 22:41:56 +00:00
Ben Langmuir
77035c07b0 Add protocol extension results to lookupVisibleMemberDecls
...and the first batch of code-completion tests for protocol
extensions.  Just the simple cases at this point.

Swift SVN r27400
2015-04-17 04:13:19 +00:00
Ben Langmuir
5f2bcba8ba Update tests for code-completion modulename change
Add module name to OtherModule result output and update the tests
accordingly.

Swift SVN r26262
2015-03-18 16:40:28 +00:00
Xi Ge
1b6808a809 [CodeCompletion] When code completing a parameter whose type
is autoclosure, we show the the parameter is of the output
type of the closure, instead of the closure itself.
rdar://19715527

Swift SVN r25590
2015-02-27 02:48:58 +00:00
Xi Ge
7f668e7b49 Add isUserAccessible() in Decl to show whether swift users should know such decl exists. For instance, a.storage for lazy var a is a inaccessible decl. An implicit decl is not necessarily inaccessible, for instance, self.
Fixing rdar://18760063

Swift SVN r25556
2015-02-26 19:16:54 +00:00
Xi Ge
f40003b0b1 Disallow the insertion of attributes such as @autoclosure in code complete string. fixing rdar://19710757
Swift SVN r25523
2015-02-25 00:52:16 +00:00
Denis Vnukov
152df92966 [CodeCompletion] Code Completion String getName should always return non-empty string value for
valid code completions. Code completion tests call and validate getName’s result. 

A minor fix for code completion fro subscripts.



Swift SVN r25101
2015-02-09 22:32:05 +00:00
Doug Gregor
b642c555be Allow one to change the argument labels of curried function parameters.
Curried function parameters (i.e., those past the first written
parameter list) default to having argument labels (which they always
have), but any attempt to change or remove the argument labels would
fail. Use the fact that we keep both the argument labels and the
parameter names in patterns to generalize our handling of argument
labels to address this problem.

The IDE changes are due to some positive fallout from this change: we
were using the body parameters as labels in code completions for
subscript operations, which was annoying and wrong.

Fixes rdar://problem/17237268.

Swift SVN r24525
2015-01-19 22:15:14 +00:00
Dmitri Hrybenko
3b04d1b013 tests: reorganize tests so that they actually use the target platform
Most tests were using %swift or similar substitutions, which did not
include the target triple and SDK.  The driver was defaulting to the
host OS.  Thus, we could not run the tests when the standard library was
not built for OS X.

Swift SVN r24504
2015-01-19 06:52:49 +00:00
Chris Lattner
8c6b2b6b5f adjust testsuite to put @autoclosure on decls instead of types, and remove a
couple of soon-to-be-invalid cases.



Swift SVN r24074
2014-12-22 20:14:11 +00:00
Dmitri Hrybenko
045eca49ef Code completion: when preparing a pattern for closure expansion in function
parameters, don't consider autoclosures to be expandable

rdar://17842781


Swift SVN r21006
2014-08-04 12:17:33 +00:00
Dmitri Hrybenko
21dd66b6cc Code completion: don't adjust implicitly unwrapped optional types to normal
optionals

rdar://17732126


Swift SVN r20212
2014-07-19 18:41:41 +00:00
Doug Gregor
2f3f6acf21 Make "true" and "false" Boolean literal constants for the BooleanLiteralConvertible protocol.
Introduce the new BooleanLiteralConvertible protocol for Boolean
literals. Take "true" and "false" as real keywords (which is most of the
reason for the testsuite churn). Make Bool BooleanLiteralConvertible
and the default Boolean literal type, and ObjCBool
BooleanLiteralConvertible. Fixes <rdar://problem/17405310> and the
recent regression that made ObjCBool not work with true/false.


Swift SVN r19728
2014-07-09 16:57:35 +00:00
Ben Langmuir
dfbd8b794f Don't desugar paren type when code-completing func params
We want to complete foo(p: (Int, Int)) as foo({#(p): (Int, Int)#}), not
as foo({#Int#}, {#Int#}).  Also, make initializers go through the
function parameter code path rather than the enum one, since we don't
want to recursively find parameters in tuples.

<rdar://problem/17461862>

Swift SVN r19514
2014-07-03 15:45:05 +00:00
Ben Langmuir
b31a6d125d Preserve vararg... syntax in code completions
Int... should now be shown as Int... rather than [Int].

Swift SVN r19464
2014-07-02 15:05:59 +00:00
Doug Gregor
55df89aabe Print array types as [T] instead of T[].
Swift SVN r19195
2014-06-25 23:59:51 +00:00
Doug Gregor
9210cd5ff4 Replace T[] array syntax with [T] in the test suite
Swift SVN r19192
2014-06-25 23:39:24 +00:00
Sonny Falk
795be8545b [IDE/CodeCompletion] Make addParamPatternFromFunction() iterate over inputType
instead, so it picks up substituted types. BodyParamPatterns is now only
used for the local non-api parameter name. 
Consolidate the two variations of addFunctionCallPattern() into one function.
Update the tests accordingly.
This addresses <rdar://problem/16956363>.

Swift SVN r18481
2014-05-21 05:47:10 +00:00
Sonny Falk
a2680240c0 [IDE/CodeCompletion] Teach code completion to display the local parameter name
if there's no parameter API name. This is for display purposes only.
Update all relevant tests accordingly.
This addresses <rdar://problem/16768768>.

For example:
  class X {
    func f(a: Int, b: Int) { }
  }

Would previously display like this in code completion in Xcode:
  f(<#Int#>, b: <#Int#>)

The local parameter name, while not API, often still conveys meaning
to the user. So it's now included like this:
  f(<#a: Int#>, b: <#Int#>)

Swift SVN r18403
2014-05-19 08:31:10 +00:00
Sonny Falk
22633c2d83 [IDE/CodeCompletion] Make code completion include the leading paren in calls.
The leading paren is included for display purposes only, not inserted
in the code if already present. It makes the displayed text in the
code completion list symmetrical with respect to open/close parens.

Add markups when printing annotation chunks so it becomes testable.
Update tests accordingly, and include tests for leading parens.

This addresses <rdar://problem/16918310>.

Swift SVN r18126
2014-05-15 21:09:56 +00:00