Commit Graph

135 Commits

Author SHA1 Message Date
Alex Hoppen
cbbca3801f [CodeCompletion] Teach TypeCheckASTNodeAtLocRequest to check initializers
This simplifies the logic in `ide::typeCheckContextAt` and fixes an issue that prevent code completion from working inside variables that are initialized by calling a closure.

Fixes rdar://90455154 [SR-16012]
Fixes rdar://85600167 [SR-15495]
2022-04-04 14:41:59 +02:00
Alex Hoppen
56ea3341f5 [CodeCompletion] Migrate ForEachSequence and PostfixExprBeginning to solver-based 2022-03-23 13:03:56 +01:00
Alex Hoppen
190ee6ecc7 [CodeCompletion] Replace includes of CodeCompletion.h by more specific ones 2022-02-23 17:08:26 +01:00
Pavel Yaskevich
d0fc580623 [IDE] Skip complex closures while checking pattern bindings
This preserves previous behavior where multi-statement closures
where always type-checked without context.
2021-12-03 10:54:56 -08:00
Pavel Yaskevich
bc54bc6bb7 Revert "[TypeChecker] SE-0326: Enable multi-statement closure inference by default" 2021-11-29 17:26:08 -08:00
Anthony Latsis
6e764aa26c TypeResolution: Remove the last remaining use of 'forContextual' 2021-11-19 16:46:20 +03:00
Pavel Yaskevich
ceb6d7e2b0 [IDE] Skip complex closures while checking pattern bindings
This preserves previous behavior where multi-statement closures
where always type-checked without context.
2021-11-15 16:42:05 -08:00
Hamish Knight
3e28bbbd2c Update for review feedback
- Remove OriginalArguments in favor of storing the
pre-rewritten argument list, which simplifies things
nicely
- Adopt llvm::indexed_accessor_iterator
2021-09-01 18:40:29 +01:00
Hamish Knight
78d8d09b99 [IDE] Adopt ArgumentList 2021-09-01 18:40:26 +01:00
Holly Borla
9f71ee1b0a Merge pull request #38766 from hborla/wrapped-argument-conversions
[Property Wrappers] Fix a bug where wrapped arguments were not properly coerced to the wrapper generator input type.
2021-08-06 13:36:37 -04:00
Holly Borla
28caecbc0f [Sema] Generalize PropertyWrapperInitializer to work with regular wrapped
properties.
2021-08-05 11:54:00 -04:00
Rintaro Ishizaki
0580357a05 Merge pull request #38044 from rintaro/ide-completion-rdar79092374
[CodeCompletion] Allow unresolved types in Callee analysis
2021-08-02 09:40:31 -07:00
Rintaro Ishizaki
013333b0d7 [CodeCompletion] Allow unresolved types in Callee analysis
struct Generic<T> {
    init(destination: T, isActive: Bool) {  }
  }

  invalid {
    Generic(destination: true, #^COMPLETE^#)
  }

In this case, since `invalid { ... }` cannot be type checked.
`ExprContextAnalysis` tries to type check `Generic` alone which resolves
to bound `Generic` type with an unresolved type. Previously, we used to
give up the analysis when seeing unresolved type. That caused mis callee
analyis.

rdar://79092374
2021-06-22 17:31:44 -07:00
Alex Hoppen
e4b42c6af0 [IDE] Complete enum argument labels in unresolved member completions
Previously, we weren’t suggesting argument labels of enum elements when doing an unresolved member completion. Treat `EnumElementDecl` similar to static `AbstractFunctionDecl`s to show their argument labels.

Fixes rdar://78780690 [SR-14689]
2021-06-21 14:50:17 +02:00
Rintaro Ishizaki
27639c20dd [CodeCompletion] Lenient argument label checking if matching overload not found
If label-matching overload is not found, try to find a position with
lenient label matching.
2021-05-18 09:17:32 -07:00
Rintaro Ishizaki
8d63f298c1 [CodeCompletion] Don't suggest argument labels from unapplicable overload
When matching an argument to a parameter list, if there is no matching
parameter, the argument list is not applicable to the parameters. In
such case, code completion should not suggest argument labels of the
function.

rdar://77867723
2021-05-17 13:39:43 -07:00
Rintaro Ishizaki
a08e3e58a7 [Completion] Look through implicit expr when collecting possible callees
For example:
  class Base {
    init(_: Int) {}
    convenience init(_: Int) { self.init() }
  }
  class Derived: Base {
    convenience init(sub: Int) { self.init(sub) }
  }
  Derived(#^HERE^#

In this case, the call is type checked to 'Base.init(_:)' and 'Derived'
is wrapped with 'MetatypeConversionExpr' with type 'Base.Type'. We need
to look through it to get the 'TypeExpr' with 'Derived.Type'.

rdar://74233797
2021-04-28 18:47:08 -07:00
Alex Hoppen
727c11dc4f Merge pull request #37037 from ahoppen/pr/vararg-label-completion
[CodeCompletion] Fix code suggestions for arguments in vararg followed by normal arg
2021-04-23 21:33:06 +02:00
Alex Hoppen
2392e79ec9 [CodeCompletion] Fix code suggestions for arguments in vararg followed by normal arg
For a function and call like
```swift
func test(_: Foo..., yArg: Baz) {}
test(.bar, #^COMPLETE^#)
```
the parser matches the code completion token to the `yArg` with a missing label, because this way all parameters are provided. However, because of this we don’t suggest any variables that could belong the the previous vararg list.

To fix this, if we encounter such a situation (argument without label after vararg), manually adjust the code completion token’s position in params to belong to the vararg list.

Fixes rdar://76977325 [SR-14515]
2021-04-23 17:23:57 +02:00
Azoy
9ed732f0ab Introduce isDecl and getDeclType
fix enum logic issue

fix tests

guard against null types
2021-04-20 02:22:16 -04:00
Alex Hoppen
f96548820d [CodeComplete] Complete argument labels in generic initializer
The actual fix is to perform qualified lookup on a TypeExpr in `collectPossibleCalleesForApply`.

This changes the behaviour of some test cases in `complete_multiple_trailingclosure.swift`, which now provide argument labels. To make the choices suggested less verbose, I refined the parameter matching to only match trailing closures to parameters of function types.

In `INIT_FALLBACK_1` we technically shouldn't be suggesting `arg3` based on the matched argument types (the closure returns `Int` and the constructor with `arg3` requires the closure to return `String`), but AFAICT we aren't doing type-checking at this stage, so there's no way to rule it out.
2021-04-12 10:10:01 +02:00
Alex Hoppen
7e536ff365 [CodeComplete] Complete argument labels after vararg
Currently, if the code completion token is after a label that refers to a vararg, it is part of that VarargExpansionExpr, so we don’t suggest the subsequent parameter’s label.

Add special handling to detect this situation and suggest the parameter label.

Fixes rdar://76355192
2021-04-08 19:33:30 +02:00
Alex Hoppen
433d7564a4 [CodeComplete] Match argument labels when completing function arguments
Previously, we always assumed that the position in the arguments would match the position in the parameter, which isn’t true in case of defaulted arguments. Try matching parameters based on argument labels to give better completion results.

Fixes rdar://60346573
2021-03-25 20:54:07 +01:00
Alex Hoppen
11df457563 [CodeComplete] Complete parameter labels in self.init call
The `init` of `self.init` needs to be looked up on the Metatype of `self`, not on the type of `self` itself. We were already doing a similar special-casing for `super.init`, which I extened to also cover `self.init`.

Resolves rdar://36521732
2021-03-23 09:27:58 +01:00
David Zarzycki
c0ec6c3235 [AST] NFC: Make ExtInfo param Optional<>
While it is very convenient to default the ExtInfo state when creating
new function types, it also make the intent unclear to those looking to
extend ExtInfo state. For example, did a given call site intend to have
the default ExtInfo state or does it just happen to work? This matters a
lot because function types are regularly unpacked and rebuilt and it's
really easy to accidentally drop ExtInfo state.

By changing the ExtInfo state to an optional, we can track when it is
actually needed.
2021-03-09 05:57:39 -05:00
Holly Borla
b821c8d76b [Sema] Add an implicit applied property wrapper expression and a new
dedicated initializer context for this expressions.
2021-02-25 18:35:14 -08:00
Rintaro Ishizaki
918ac8c1eb [CodeCompletion] Don't try to re-typecheck ClosureExpr
At the every usage of 'collectPossibleReturnTypesFromContext()', the
closure must have been typechecked earlier. If the closure has no
valid type at this point, there's no chance to be type-checked by
re-typechecking.

rdar://problem/74430478
2021-02-19 19:16:02 -08:00
Nathan Hawes
240a26244d [CodeCompletion] Rename isSingleExpressionBody to isImplicitSingleExpressionReturn for clarity
This bool was true only for single-expression closure and function bodies that
do not have an explicit `return` in the source. Rename it and its associated
methods, to avoid confusion with the hasSingleExpressionBody methods on
ClosureExpr and AbstractFuncDecl. Those don't care whether the expression was
explicitly written in the source or not.
2020-11-19 13:33:57 +11:00
Pavel Yaskevich
51bd8d93d6 Merge pull request #34510 from maustinstar/sr-11711
[SR-11711]  [Parse] Single-expression implicit returns within #if declarations
2020-11-05 21:14:44 -08:00
Rintaro Ishizaki
d221f14215 [CodeCompletion] Deduplicate results in ExprContextInfo
Using canonical types. Otherwise 'Optional<T>' and 'T?' aren't
considered the same.

Also, for example, the expected context types are 'T?' and 'T', don't
get results from 'T' twice.

rdar://problem/71063455
2020-11-05 11:32:16 -08:00
maustinstar
037edf3a8c [SR-11711] Refactor shared parser code for single-expression returns 2020-11-03 22:03:11 -05:00
maustinstar
37b17338e5 [SR-11711] Single-expression returns for #if declarations within functions 2020-11-03 12:47:39 -05:00
Slava Pestov
dbdbbff743 SILParser: Overhaul to not rely on parse-time lookup 2020-09-11 20:05:47 -04:00
Nathan Hawes
198687018c [IDE] Fix typo to address unused warning (NFC) 2020-08-29 08:06:09 -07:00
Nathan Hawes
3e8278ae71 Merge pull request #33676 from nathawes/parser-completion-fixes
[Parse][IDE] Various parser fixes for code completion
2020-08-28 22:11:31 -07:00
Nathan Hawes
3e0500d73c [Parse][IDE] Don't drop default argument init exprs containing code completion exprs and type check them for code completion.
Fixes up some tests marked as non-ideal to give the ideal result now too.
2020-08-28 17:09:37 -07:00
Rintaro Ishizaki
c48a676a1c Merge pull request #31679 from Jumhyn/implicit-member-chains-different-types
[SE-0287] [Sema] Implementation for implicit member chains
2020-08-28 10:47:53 -07:00
Rintaro Ishizaki
e013ebd388 [CodeCompletion] Ensure all ExtensionDecl's extended nominal are computed
Fixes an assertion failure in ASTScope lookup

rdar://problem/67102794
2020-08-27 16:17:43 -07:00
Frederick Kellison-Linn
352adc3b5d Remove Argument from UnresolvedMemberExpr
Instead, an expresison like `.foo()` is represented as an `UnresolvedMemberExpr` nested inside a `CallExpr`.
2020-08-26 22:42:30 -04:00
Suyash Srijan
a577a87f99 [ExprContextAnalysis] Look into base type of optional as well when collecting callees for unresolved member (#33292) 2020-08-05 12:54:05 +01:00
Rintaro Ishizaki
69d8398b04 Merge pull request #33270 from rintaro/ide-completion-typecheckcontextat
[CodeCompletion] Cleanup typeCheckContextAt()
2020-08-04 15:53:18 -07:00
Anthony Latsis
78f0259bfb Merge pull request #33283 from AnthonyLatsis/type-locura-2
ASTWalker: Offload TypeLoc
2020-08-05 00:17:33 +03:00
Robert Widmann
b50a2cf430 Merge pull request #33251 from AnthonyLatsis/type-locura-1
Rid performTypeLocChecking of TypeLoc
2020-08-04 12:04:10 -07:00
Anthony Latsis
7bcc4baa33 [NFC] TypeLoc: Rid performTypeLocChecking off TypeLoc 2020-08-04 19:15:55 +03:00
Anthony Latsis
b26310ee97 TypeLoc: Offload TypeLoc off the ASTWalker 2020-08-04 18:13:28 +03:00
Rintaro Ishizaki
ec8637c197 [CodeCompletion] Cleanup typeCheckContextAt()
There's no need of separate 'Impl' function
2020-08-03 15:31:12 -07:00
Rintaro Ishizaki
3e558f064f [CodeCompletion] Handle @autoclosure in context type analysis
If the context is '@autoclosure' parameter, the context type should be
the result type of it.

rdar://problem/65802490
2020-07-30 14:58:26 -07:00
Rintaro Ishizaki
12762a2a30 [CodeCompletion] Only type check related statements in function body
Introduce 'TypeCheckSingleASTNode' mode that only type checks single body
element and dependent necessities (i.e. referencing ValueDecls and their
dependencies).

Renamed swift::typeCheckAbstractFunctionBodyAtLoc() to
swift::typeCheckASTNodeAtLoc(DeclContext *, SourceLoc). That type checks
innermost 'ASTNode' at the location. Also, 'TypeCheckSingleASTNode' mode
skips type checking any "body" of the node (i.e. BraceStmt elements for
function body, if statement body, closure body, etc.)

Added on-demand type checking using it:
 - VarDecl in TapExpr
 - ParamDecl in ClosureExpr
 - Return type of ClosureExpr
 - Binding value in control statements
   (e.g. ForEachStmt, SwitchStmt, DoCatchStmt, etc.)

rdar://problem/63932852
2020-07-24 10:48:51 -07:00
Rintaro Ishizaki
dab216dc49 [CodeCompletion] Use TypeContextInfo to get expected return types
If the type check return type from the context has unresolved types, it
can't be used for checking convertibility. Fallback to get
'TypeContextInfo' of the closure position.

rdar://problem/66002497
2020-07-23 14:34:54 -07:00
Suyash Srijan
58a84ea4c1 [NFC] Cleanup some code to use 'swift::getParameterList(ValueDecl)' to fetch parameter lists (#32979) 2020-07-20 19:50:37 +01:00