Commit Graph

63 Commits

Author SHA1 Message Date
Marc Rasi
5772ddda7e fix autocomplete crash 2020-03-20 14:43:46 -07:00
Rintaro Ishizaki
62078c79dd [ASTPrinter/CodeCompletion] Stop printing base type when possible
rdar://problem/57033931
2019-12-17 16:26:37 -08:00
Rintaro Ishizaki
ad4b9df3c0 [CodeCompletion] Suggest the property name in its didSet clause
Previously, property names are hidden in the whole range of the
declarations. Now, it's only hidden in its own initializer range.

rdar://problem/49697202
2019-12-03 18:12:47 -08:00
Slava Pestov
44827bbde4 IDE: Refactor LookupVisibleDecls to use standard override/shadowing logic
There's no need to roll our own implementation here.

Fixes <rdar://problem/16724197>.
2019-09-25 22:17:56 -04:00
Rintaro Ishizaki
4353a55587 [CodeCompletion] Fix a crash in collectPossibleCalleesByQualifiedLookup
We cannot assume that 'FuncDecls' have 'AnyFunctionType' interface type
or null type. They can be 'ErrorType's.

rdar://problem/54215016
2019-08-12 12:27:30 -07:00
Rintaro Ishizaki
7b7c320bd5 [CodeCompletion] Allow ErrorType in constructor
Even if the constructor has `ErrorType` we can suggest it as long as it's
`FunctionType`.

rdar://problem/49480808
2019-05-13 01:32:57 -07:00
Ben Langmuir
e255bac6be [code-completion] Fix type context for single-expression implicit getter
This adds an implicit body so that we can dig out the return type
context the same way as a normal function. For now, we are also treating
the first expression in a multi-statement implicit getter body the same
way; we'll need to refactor how we complete in accessors to
differentiate those cases.
2019-03-26 16:45:32 -07:00
Rintaro Ishizaki
c99af83901 [CodeCompletion] Consolidate parameter list processing funcitons
There were 2 functions to output argument list. Consolidate them and
consistently use it from every call like production (i.e. function call,
constructor call, enum with associated values, subscript)
2019-03-05 16:45:48 -08:00
Rintaro Ishizaki
82b5f2a195 [CodeCompletion] Find parsed expression from typechecked decl context
Instead of re-typechecking parsed expression, find typechecked
expression that corresponds to the parsed expression from the
typechecked decl context, because the sub expressions of the parsed
expression can be weirdly mutated/replaced by decl context typechecking.

rdar://problem/48141174
2019-02-28 18:39:46 -08:00
Slava Pestov
f7e39447a7 LookupVisibleDecls: Find generic parameters in methods inside extensions
The logic here had diverged from UnqualifiedLookup. One day we'll merge
the two, for now clean it up a bit to match.

Note that all generic parameters now have 'Reason' reported as 'Local'.
I don't believe this really matters.

Fixes <rdar://problem/20530021>.
2019-01-08 16:51:20 -05:00
Rintaro Ishizaki
d86725cf80 [ConstraintSystem] Ignore patterns in linked expression analysis (#18487)
Fixes an assertion hit in "pattern in binary expression" case.

rdar://problem/41071587
2018-08-04 11:26:09 +09:00
Rintaro Ishizaki
bcb83acfe9 [AST] Fix a crash in UnqualifiedLookup
Add null type check for `Self` type in `UnqualifiedLookup`. It seems this
doesn't happen in normal compilation. But when code-completion happens in
inactive conditional compilation block, since surrounding context hasn't
been typechecked, `Self` type can be null.

rdar://problem/41234606
2018-07-27 15:47:26 +09:00
Rintaro Ishizaki
9e7fa99689 [CodeComplete] Use PrintOptionalAsImplicitlyUnwrapped to print IUO
Other instances of fb9c65e. Consistently use
PrintOption.PrintOptionalAsImplicitlyUnwrapped to print IUO.

rdar://problem/41046225
rdar://problem/42443512
2018-07-26 07:55:25 +09:00
Rintaro Ishizaki
2babbc3a44 [CodeComplete] Handle ternary expression in sequence completion
Follow-up to f577578a6a. The same
treatment for ternary expression (IfExpr). Plus, fix a regression
introduced in f577578a where infix operators were disappeard from
results.
2018-07-25 13:59:20 +09:00
Rintaro Ishizaki
4c0892fdc6 [CodeComplete] Strip out try and optional eval expr in operator compilation
foldSequence() may hoist these expression up by mutating their sub
expression. When completing operators, this behavior ruins reusability
of operand. Since these expression doesn't affect completion, we can
strip them out.

rdar://problem/42452085
2018-07-25 13:58:53 +09:00
Rintaro Ishizaki
fb9c65e108 [CodeComplete] Fix crasher when completing inout IUO variable
Use `PrintOptionalAsImplicitlyUnwrapped` option.

rdar://problem/40956846
2018-07-14 00:52:57 +09:00
Rintaro Ishizaki
52e3109231 [CodeComplete] Restore original type in getOperatorCompletions
In getOperatorCompletions(), for each every known operators, temporary
expressions are created and typechecked. In this process, typechecker
may set the type of the parsed expression. That may cause non-accurate
completion results or crash at worst.

rdar://problem/28188259
2018-06-27 19:35:25 +09:00
Rintaro Ishizaki
8c970ab26d [CodeComplete] Handle assign expression in sequence completion
rdar://problem/41232519
rdar://problem/41159258
2018-06-27 19:35:25 +09:00
Slava Pestov
edc3b7bfc3 Migrate IDE tests to Swift 4
I couldn't update complete_func_reference. Fixing the problem there
is tracked by rdar://problem/41496748.
2018-06-26 16:56:33 -07:00
Slava Pestov
5d2752f7d2 Run tests with -swift-version 4 by default
Some test now fail, so add an explicit -swift-version 3.
2018-06-19 23:24:19 -07:00
Robert Widmann
1beb75583a Push FunctionTypeRepr Input Invariants Up
Validation of the input side of FunctionTypeRepr was previously being done in Sema because of expression folding.  If we instead push the invariant that the input TypeRepr should always be a TupleTypeRepr into the AST a number of nice cleanups fall out:

- The SIL Parser no longer accepts Swift 2-style type declarations
-  Parse is more cleanly able to reject invalid FunctionTypeReprs
- Clients of the AST can be assured the input type is always a TupleType so we can flush Swift 2 hacks
2018-06-13 18:41:20 -07:00
fischertony
7b41a41fb6 updated tests & added completions for postfixExpr 2018-05-12 09:05:57 +03:00
Pavel Yaskevich
a014842696 [CSBindings] Look through non-value types earlier to avoid producing incorrect bindings
Before checking any requirements of the binding type, let's look
through @autoclosure and/or non-variable types if source constraint
requires that, otherwise we'd end up creating bindings for types
which later on might end up causing infinite recursion like dependent
member types in result position of @autoclosure parameter.

Resolves: rdar://problem/38272904
2018-04-05 00:11:15 -07:00
Nathan Hawes
136b5eff8b [CSGen][CSDiag] Update SanitizeExpr to santize OpenExistentialExpr
They can show up when re-typechecking via diag or code-completion and were
only being sanitized out in one place in CSDiag. Moved that logic into
SanitizeExpr.

Resolves rdar://problem/38149042
2018-04-02 11:42:09 -07:00
Doug Gregor
e82e7ee908 [Type checker] Use BoundNameAliasType for all typealiases.
Rather than relying on the NameAliasType we get by default for references
to non-generic typealiases, use BoundNameAliasType consistently to handle
references to typealiases that are formed by the type checker.
2018-03-25 21:35:16 -07:00
Ben Langmuir
642ae90a86 [code-complete] Reduce the priority of function call patterns
Constructor call patterns already get a real priority, but because of
the way we do function call patterns we don't have enough information,
and previously we were setting it to "expression specific", which is
unnecessarily high, particularly since functions (unlike inits) have
other better ways to code-complete already.

rdar://31113161
2017-12-18 12:55:20 -08:00
Ben Langmuir
b6d5a1f1a5 [code-complete] Do not insert rparen after a call pattern completion
When completing
  Foo(<here>
We will now provide
  bar: <#value#>
instead of
  bar: <#value#>)

Inserting the rparen caused some problems in practice:
* the old behaviour optimized for typing Foo(<complete> instead of
  Foo(<complete>), which can conflict with user behaviours or ...
* in editors with automatic brace-matching, we often conflicted with the
  editor, leading to extraneous closing parens

And in general, it is much more predictable for tooling to either insert
matching ( and ) or to not insert either.  While this change may not be
ideal For users of editors that do not do automatic brace-matching, I
believe it is still better overall to have to type a missing paren than
to have to delete an extraneous one.

rdar://31113161
2017-12-18 11:59:49 -08:00
Slava Pestov
c197df6e7f Sema: Fix type checking without applying solution in presence of anonymous closure parameters
Even if we don't apply the solution, we still end up writing
types into ParamDecls of closures contained the expression.

Make sure this is idempotent by disabling 'cleanup', which
avoids setting them to ErrorTypes, and teaching ExprCleaner
to clear out types of VarDecls.

This is a hack that will get better once the constraint
system type map stuff is further along.

Fixes <rdar://problem/33219081>.
2017-07-11 17:00:35 -07:00
Huon Wilson
8c8f35ee78 [Parse] Don't tell CodeCompletion nonsense about protocol/AT where clauses.
This doesn't give particularly useful information yet (i.e. Self isn't
listed, see rdar://problem/31981641 ), but it does stop the completion
code from just directly crashing.

Fixes rdar://problem/31981486.
2017-05-12 16:00:00 +10:00
Xi Ge
911f7b1805 [CodeCompletion] Using the default constraints generator for TupleExpr (#5557)
[CodeCompletion] Using the default constraints generator for TupleExpr
when inferring the type of unresolved members. rdar://28991372

When code completing, we used to create a type variable to represent the type
of an entire tuple expression. However, recent improvements on parser make this
step unnecessary and crash-prone. Thus, we use the default constraint
generator to interpret tuple expressions.
2016-10-31 12:00:50 -07:00
Argyrios Kyrtzidis
69918a966d [ASTPrinter] Fix printing of nested typealias types and make it consistent with printing of nominal types.
This fixes several issues:
- By default parent types of alias types are not printed which results in
	- Erroneous fixits, for example when casting to 'Notification.Name' from a string, which ends up adding erroneous cast
	  as "Name(rawValue: ...)"
	- Hard to understand types in code-completion results and diagnostics
- When printing with 'fully-qualified' option typealias types are printed erroneously like this "<PARENT>.Type.<TYPEALIAS>"

The change make typealias printing same as nominal types and addresses the above.
2016-08-11 12:15:15 -07:00
Dmitri Gribenko
d175b3b66d Migrate FileCheck to %FileCheck in tests 2016-08-10 23:52:02 -07:00
Doug Gregor
b9363fe6bd [SE-0111] Enable SE-0111 by default. 2016-07-29 17:28:24 -07:00
Robert Widmann
f97e5dcb0e [SE-0115][1/2] Rename *LiteralConvertible protocols to ExpressibleBy*Literal. This
change includes both the necessary protocol updates and the deprecation
warnings
suitable for migration.  A future patch will remove the renamings and
make this
a hard error.
2016-07-12 15:25:24 -07:00
Chris Lattner
ffcafd7c00 fix the AST printer to stop omitting parens around "simple enough" parameter
lists.
2016-07-02 20:24:58 -07:00
Manav Gabhawala
7928140f79 [SE-0046] Implements consistent function parameter labels by discarding extraneous parameter names and adding _ where necessary 2016-04-06 20:21:58 -04:00
Dmitri Gribenko
efaa39ea79 stdlib: add first argument labels and some other changes to conform to API guidelines 2016-02-15 23:47:54 -08:00
Doug Gregor
7d70b704e4 Merge commit '5e11e3f7287427d386636a169c4065c0373931a8' into swift-3-api-guidelines 2016-01-19 23:18:20 -08:00
Xi Ge
ca873a9629 [CodeCompletion] Add null check to prevent assertion violations. rdar://22769393 2016-01-14 15:31:32 -08:00
Chris Lattner
78be05921d Revert a testcase change I made in 7daaa22, which doesn't seem correct. 2015-12-31 20:12:12 -08:00
Chris Lattner
7daaa22d93 Completely reimplement/redesign the AST representation of parameters.
Parameters (to methods, initializers, accessors, subscripts, etc) have always been represented
as Pattern's (of a particular sort), stemming from an early design direction that was abandoned.
Being built on top of patterns leads to patterns being overly complicated (e.g. tuple patterns
have to have varargs and default parameters) and make working on parameter lists complicated
and error prone.  This might have been ok in 2015, but there is no way we can live like this in
2016.

Instead of using Patterns, carve out a new ParameterList and Parameter type to represent all the
parameter specific stuff.  This simplifies many things and allows a lot of simplifications.
Unfortunately, I wasn't able to do this very incrementally, so this is a huge patch.  The good
news is that it erases a ton of code, and the technical debt that went with it.  Ignoring test
suite changes, we have:
   77 files changed, 2359 insertions(+), 3221 deletions(-)

This patch also makes a bunch of wierd things dead, but I'll sweep those out in follow-on
patches.

Fixes <rdar://problem/22846558> No code completions in Foo( when Foo has error type
Fixes <rdar://problem/24026538> Slight regression in generated header, which I filed to go with 3a23d75.

Fixes an overloading bug involving default arguments and curried functions (see the diff to
Constraints/diagnostics.swift, which we now correctly accept).

Fixes cases where problems with parameters would get emitted multiple times, e.g. in the
test/Parse/subscripting.swift testcase.

The source range for ParamDecl now includes its type, which permutes some of the IDE / SourceModel tests
(for the better, I think).

Eliminates the bogus "type annotation missing in pattern" error message when a type isn't
specified for a parameter (see test/decl/func/functions.swift).

This now consistently parenthesizes argument lists in function types, which leads to many diffs in the
SILGen tests among others.

This does break the "sibling indentation" test in SourceKit/CodeFormat/indent-sibling.swift, and
I haven't been able to figure it out.  Given that this is experimental functionality anyway,
I'm just XFAILing the test for now.  i'll look at it separately from this mongo diff.
2015-12-31 19:24:46 -08:00
Dmitri Gribenko
31598d41bf Rename GeneratorType to IteratorProtocol 2015-12-07 17:08:32 -08:00
Xi Ge
578f1370d2 [CodeCompletion] For types with type parameters, their constraint extensions are considered unusable. rdar://23173692 2015-12-04 12:02:45 -08: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
Ben Langmuir
be016aedf3 [CodeCompletion] Don't add empty code completion on invalid init
For now, just avoid adding the completion since that will assert later
when we try to sort. In the future we could actually complete something
useful here, since we can dig out the names of the parameters even if
the type is invalid.

rdar://problem/22834017

Swift SVN r32211
2015-09-24 22:13:13 +00:00
Ben Langmuir
94f6eec8ef [CodeCompletion] Don't try to lookup members of a null type
rdar://problem/22835966

Swift SVN r32207
2015-09-24 20:03:32 +00:00
Ben Langmuir
41c7a28120 [CodeCompletion] Avoid salvaging when code completing expressions
Salvaging can try to apply a solution when producing diagnostics, and we
can't generally apply solutions in code completion because they may
contain free type variables.

rdar://problem/22836263

Swift SVN r32203
2015-09-24 18:49:43 +00:00
Ben Langmuir
3fdfd1a05a [CodeCompletion] Fix assertion failure with curried function
Remove some untested broken code that I am fairly sure could never find
the correct FunctionDecl.

rdar://problem/22688199

Swift SVN r32000
2015-09-16 18:03:32 +00:00
Ben Langmuir
0a43e5460f [CodeComplete] Don't try to lookup members of null type
rdar://problem/22012123

Swift SVN r31639
2015-09-02 21:16:48 +00:00
Xi Ge
a587c3be53 Check if an extended type is null before further look up. rdar://22036358
Swift SVN r31012
2015-08-04 22:10:04 +00:00